Table of Contents

cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)
Header Files (Local and System), C Standard Library (Libc), Libraries
arithmetic (equations, operators)
logic and operators (and, or, not, xor)
Variables (types, ranges, sizes)

Scope (Block, Local, Global, File)
Pointers (address of, assignment, dereferencing)
Type Casting
Selection Structures (if, case/switch)
Repetition/Iteration Structures (for, while, do while)

Arrays (standard notation, pointer arithmetic, single-dimensional, multi-dimensional)
File Access (Read, Write, Append)
Structures (Declaration, Accessing Elements, Pointers to)
typedef, enum, union
Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments
Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)
I/O Streams (cin, cout, cerr, stream operators) [C++]
Namespaces [C++]
Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]
Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]
Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]
Overloading (Functions, Operators) [C++]
Exception Handing (throw, try, catch) [C++]
Templates, STL (Standard Template Library) [C++]

cprog Keyword 1

Header Files

Definition

A header file is used to allow the programmer to use specific functions. It is used by preceding it with '#include'. (Ex. #include<stdio.h>)

Demonstration

Demonstration of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    printf("This is an example of a header file - stdio.h")
 
    return(0);
}

cprog Keyword 2

Standard I/O

Definition

Standard I/O stands for Standard Input/Output. When in a program, it allows the user to input whatever they need to put into the program, and it allows the program to show text, which can say whatever the programmer wants.

Demonstration

Demonstration of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code here.
 */
#include <stdio.h>
 
int main()
{
    unsigned char randomvar;
    printf("This is the output code - printf. It outputs whatever the programmer wants through text.");
    scanf("%hhu", &randomvar); /* Allows the user to input whatever data
                                * that is necessary.
                                * /
    return(0);
}

cprog Keyword 3

Repetition/Iteration Structures

Definition

Repetition/Iteration Structures consist of for, while, and do-while loops. Each of these loops are often used to fill arrays, accept values and keep asking if the value isn't correct, to accept multiple values, to print multiple values, etc.

Demonstration

Demonstration of Repetition/Iteration Structures

/*
 * Sample code block
 */
 
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        char *value, i; //Declaring two integers: the pointer "value"
                        //and i as a char
        value = (char*)malloc(sizeof(char)*4); //setting aside 4 bits of memory
                                               //and returning a pointer
        *(value+0) = 0; //assigning the pointer for the first space of allocated$
        *(value+1) = 1; //assigning pointer for the second space of allocated me$
        fprintf(stdout, "Please enter a value (-128-+127):");
        fscanf(stdin, "%hhd", &i);
        *(value+2) = i; //assigns pointer for the third space of allocated memory
                        //gives that memory the value that it is assigned
        *(value+3) = (2*i)+3; //assigns pointer for the fourth space of allocated memory
                              //gives that memory the value that is "calculated"
        for(i=3; i>=0; i--)
        {
                printf("%hhd\n", *(value+i));
        }
        return(0);
}
 
/* What the file is doing is showing how arrays work.
 
        The first pointer assigns 0 to the first space (*(value+0) = 0)
        The second pointer assigns 1 to the second space (*(value+1) = 1)
        The third pointer assigns whatever the user input as i to the                 third space etc, etc.
*/
 
    return(0);
}

cprog Keyword 4

Variables (Type, Ranges, and Sizes)

Definition

Variables are the part of the code that take assignments like numbers or memory. There are many types of variables with different sizes.

Demonstration

Demonstration of the chosen keyword.

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
 
#include <stdio.h>
#include <math.h>
 
int main()
{
        // Signed Variables
        signed char sc = 0;
        signed short int ssint = 0;
        signed int sint = 0;
        signed long int slint = 0;
        signed long long int sllint = 0;
 
        // Unsigned Variables
        unsigned char uc = 0;
        unsigned short int usint = 0;
        unsigned int uint = 0;
        unsigned long int ulint = 0;
        unsigned long long int ullint = 0;
 
        // Junk Variable
        unsigned long long int quantity = 0;
 
    return(0);
}

cprog Keyword 5

logic and operators (and, or, not, xor)

Definition

Logic gates are used in if blocks, loops, switch blocks, and other functions. The purpose of these logic gates is to take two or more input statements and see if the output is true or false, and perform a specific task, in most cases, with that specific output. Operators are the signs that do a specific task, like add “+”, subtract “-”, etc.

Demonstration

* A few examples of operators are greater than “>”, less than “<”, is equal to “==”, etc. * A few examples of logic gates are AND “&&”, OR “||”, NOT “!=”, etc.

/*
 * Sample code block
 */
 
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
        char *word, len = 0, x, pos = 0;
        word = (char *) malloc(sizeof(char)*24);
        fprintf(stdout, "Please enter a word: ");
        fscanf(stdin, "%s", word);
        printf("Debug A\n");
        x = *(word + pos);
        while((x!='\0')&&(x != '\n')) // Specifically the "&&" and the "!="
        {
                printf("COME ON! x is %hhd\n", x);
                printf("pos is %hhd\n", pos);
                len++;
                pos++;
                x = *(word + pos);
        }
        printf("Debug B\n");
        for(pos = len; pos > -1; pos--)
        {
                fprintf(stdout, "%c", *(word + pos));
        }
        fprintf(stdout, "\n");
        printf("Debug C\n");
        return(0);
}

cprog Keyword 6

Functions, Parameters

Definition

Functions are specific blocks of code that were either created with the standard library of code or are created separately in each program. The purpose of these functions vary, but the main idea of functions is that they are created to perform a certain operation that can be used to further the process of the program that it is used in. The parameters are the variables that are called in the function, and are brought in through the function call.

Demonstration

Demonstration of the chosen keyword.

/*
 *
 * Sample code block for functions and parameters.
 *
 */
#include<stdio.h>
 
int function( int prntnum ) //I cleverly labeled the function of this program "function" and the parameter "prntnum".
{
        char i;
        for(i=0; i < 10; i++)
        {
                prntnum++;
        }
        return(prntnum);
}
 
int main()
{
        int parameter = 0;
        printf("The value of the original parameter is: %d\n", parameter);
        printf("The new value of the parameter is: %d\n", function( parameter ));
        return(0);
}

Results:

lab46:~/src/cprog/Opus/Opus1$ ./Keyword6
The value of the original parameter is: 0
The new value of the parameter is: 10
lab46:~/src/cprog/Opus/Opus1$ 

cprog Keyword 7

Selection Structures (if, case/switch)

Definition

Selection Structures are used to decide if a program will continue or which path it will take. If blocks are used with '!=' (not equal to), '&&' (and), '||' (or), etc. Case/Switch blocks are used a great amount of the time as “menus” that the user can choose from.

Demonstration

Demonstration of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block for Selection Structures
 */      
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        int *input, *pick;  input=pick=NULL;
        input=(int *)malloc(sizeof(int)*1);
        pick=(int *)malloc(sizeof(int)*1);
        *input=0;
        *pick=0;
        while(*pick != -1)
        {
                srand(time(NULL));
                *pick=rand()%99+1;
                printf("Guess the computer's pick: ");
                scanf("%d", input);
                if(*input==*pick) //This is the first if block
                {
                        printf("Wow! You got $it right!!!!\n");
                }
                else if(*input > *pick)
                {
                        printf("Too low!!!\n");
                }
                else
                {
                        printf("Too high!!\n");
                }
                printf("Computer had %d\n", *pick);
                printf("0 to go again, -1 to quit\n");
                scanf("%d", pick);
        }
        return(0);
}

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

cprog Keyword 8

Arithmetic (Equations, Operators)

Definition

Arithmetic is used to perform operations that the computer has to run so it can run programs. Equations are solved to find a result that the user is looking for. Operators are used in equations, examples are +, -, /, and *.

Demonstration

Demonstration of the chosen keyword.

/*
 * Sample code block
 */
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        FILE *in, *out;
        char value=0;
        in=fopen("file.txt", "r");
        out=fopen("out.txt", "w");
        if(in == NULL)
        {
                printf("ERROR!\n");
                exit(1);
        }
        fscanf(in, "%hhd", &value);
        while(value!=-1)
        {
                value*=2; // This is an equation, which means "value = value * 2", the operator being *
                fprintf(out, "%hhd\n", value);
                fscanf(in, "%hhd", &value);
        }
        fclose(in);
        fclose(out);
        return(0);
}

cprog Objective

cprog Objective

The objective of the course is to learn C/C++ Programming language and use that to learn about computers and programming more. Also, programming in general is important.

Definition

This includes learning about anything from arrays(blocks of memory to store similar variables) to variables. All that will be taught to me is important in taking my next step into the beautiful world of programming and technology!

Method

I will be using the books I have purchased, my professor, and other students as resources to help myself grasp the concept of computer programming and all that it controls.

Measurement

On a scale of Red to Blue, I would say I am at a well… A well of knowledge and understanding! No, but seriously, I understand most of the concepts. The trouble I have is that:

1. I procrastinate 2. Putting together my own code from scratch becomes a little troublesome, especially since I learned mostly C++ and then jumped into this new atmosphere of C, with the compiler that comes with Ubuntu and Linux.

It is all a little confusing at times, but I feel that I will get the hang of it.

Analysis

I'm still quite fuzzy on how I am to fill this out, but I am going to try my best to answer these correctly.

I apologize if this is completely incorrect. I tried to fill it out to the best of my ability. Unfortunately, my abilities are lacking at the moment because it is very late for me and once it gets late, my brain flies out the window, and it takes me a little while (and some quality sleep) to get it back and functional!