User Tools

Site Tools


opus:fall2012:asowers:cprogpart1

cprog Keyword 1

Identification of chosen keyword.

Functions

All programs contain at least a main() function. The main()function typically is executed when the program starts. functions contain parameters or instructions to be used during the programs computation. Here is an example of a function parameter:

long sum( int array[], int number ) // Identifiers
 
{                                   //body of function
 
  int i;
 
  long result = 0;       
 
 
 
  for( i = 0;  i < number;  ++i )
 
     result += (long)array[i];
 
  return result;
 
}

Functions can also have declarations before the body where you can call datatypes.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

cprog Keyword 1 Phase 2

Identification of chosen keyword.

Definition

Structs, not your mama's sneaker shoes.

Example

#include <stdio.h>
#include <stdlib.h>
 
struct mystruct {                 //
    int test;                     // Declaration of initial struct.
};                                //
 
typedef struct mystruct * newstruct;                                    // newstruct function is a pointer to my struct.
 
newstruct getnewstruct() {
    newstruct temp = (newstruct)malloc(sizeof(newstruct*)) ;
    return temp;
}
 
int main()
{
    newstruct tester = getnewstruct() ;                  //
    tester -> test = 8;                                  // Mathematical manipulation and printing of structure.
    tester -> test++;                                    //
    printf ("The value is %i\n",tester -> test) ;        //
    free(tester) ;
    return 0;
}

Demonstration

Demonstration of the indicated 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:

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

andrew ~ $ gcc malloc.c -o malloc
andrew ~ $ ./malloc
First value: 10
Pi is: 3.140000
opus/fall2012/asowers/cprogpart1.txt · Last modified: 2012/11/27 19:40 by asowers