The document discusses techniques for modularizing source code into separate files when developing large programs. It recommends splitting source code into multiple .c and .h files with each function defined in its own .c file and declared in a corresponding .h file. Header files should include function prototypes and extern declarations. Conditional compilation with #ifndef and #define is used to prevent header files from being included multiple times. This modular approach makes the code easier to maintain, compile and work on collaboratively.
The document discusses pointers in C programming. Some key points:
- Pointers store the address of a variable in memory. Pointer variables hold the address of other variables.
- To access the value of the variable a pointer points to, you dereference the pointer using *.
- Pointer variables are passed by value like other variables in C, so any changes made to the pointer or value it points to inside a function will not be reflected outside the function.
This document discusses function pointers, callback functions, functors, and the observer pattern in C and C++. It begins by explaining the syntax of function pointers and how they can point to the address of a function. It then discusses how callback functions allow a caller function to pass a function pointer as an argument, uncoupling the caller from the callee. Functors are described as functions with state that can act like functions through operator overloading. The observer pattern is explained as defining dependencies between objects so that one object (the subject) notifies observer objects of any state changes.
This document discusses structures in C programming. It explains that structures can contain elements of different data types, accessed by name, unlike arrays where all elements must be of the same type and accessed by index. It provides examples of declaring a structure type with members, defining structure variables, accessing members using the dot operator, passing structures to functions, and initializing an array of structures.
This document discusses structures in C programming. It explains that structures can contain elements of different data types, accessed by name, unlike arrays where all elements must be of the same type and accessed by index. It provides examples of declaring a structure type with members, defining structure variables, accessing members using the dot operator, passing structures to functions, and initializing an array of structures.
The document discusses call-by-value in function invocation in C. When a function is called, only the values of the arguments are passed to the function, not the variables themselves. So any changes made to the parameters inside the function are not reflected in the calling function. This causes an issue when trying to swap variables by passing them to a Swap function.
2. 2
Passing Arguments to main( )
則 Passing Arguments to main( )
Example: 襦蠏碁 蠍磯 語襯 豢ロ 覲
C:> myprog a b c d
program name: myprog
argument 1: a
argument 2: b
argument 3: c
argument 4: d
C:>
3. 3
Passing Arguments to main( )
則 Passing Arguments to main( )
C 襦蠏碁 ろ command line 譯殊伎
arguments襯 main( ) function pass.
argc : command line arguments 螳
argv : arguments value襯 覦蠍 String array
[Ex] int main(int argc, char *argv[])
[Ex] myprog c java pascal
argc = 4
argv[0] => myprog
argv[1] => c
argv[2] => java
argv[3] => pascal
4. 4
Passing Arguments to main( )
[Ex] #include <stdio.h>
int main (int argc, char *argv[]){
int count;
printf(program name: %sn, argv[0]);
if(argc > 1){
for( count=1; count < argc; count++ )
printf(argument %d = %sn, count, argv[count]);
}
else
puts(No comand line arguments);
return 0;
}
> a.out hi hello
program name: a.out
argument 1 = hi
argument 2 = hello