strings Which is an array of pointers Where each array element points to a string In other words, each array element contains the address of the 0th character of the array of characters See example program at: arraypointer.c
in read-only memory (either in the code or data segment), so we cannot change the values of the characters, or it will crash your program //Segmentation fault (core dumped) array[0][0]=‘X’;
The words that you type on the UNIX commandline The commandline arguments are stored in your program as an array of strings Each space on the commandline separates each string See example program: command.c
of commandline arguments argv - argument vector is a pointer to an array of character strings that contain the commandline arguments (also written as **argv) int main(int argc, char *argv[])
the commandline, so you might get unexpected results An apostrophe (') or double quotes (") are ignored An asterisk (*) means all matching names, so it will display all the files and directories Greater than (>) or less than (<) is for redirection
commandline arguments are stored on the runtime stack, so we can change the values of the characters, if needed argv[0][0]=‘X’;//no program crash printf(“%s”, argv[0]); // X/program
stack is the last arguments entered on the commandline name address value array[4][4] 0xffbffbbc array[4][3] 0xffbffbbb array[4][2] 0xffbffbba array[4][1] 0xffbffbb9 array[4][0] 0xffbffbb8 '\0' 'r' 'u' 'o' 'f'
The bottommost string on runtime stack is the executable program file’s name name address value argv[0][4] 0xffbffba4 argv[0][3] 0xffbffba3 argv[0][2] 0xffbffba2 argv[0][1] 0xffbffba1 argv[0][0] 0xffbffba0
address of a function A function name is the address in memory of the start of the function Function pointers can be: Passed to a function Returned to functions Stored in arrays Assigned to other function pointers
functionpointer.c Syntax to declare and initialize an array of functions: returnType (*array[SIZE](listOfParameterTypes) = {function1, function2, function3, …} Note that the return type, parameter types and parameter count have to match for each function This is because arrays store data of the same type
pointers on the runtime stack in the stack segment with address to function definitions, which are stored in the code segment name address value function definition array[2] 0xffbffa30 void function1(){printf("1st");} array[1] 0xffbffa2c void function1(){printf("2nd");} array[0] 0xffbffa28 void function1(){printf("3rd");} 0x10814 0x1080c 0x107ec
that are pointers to other functions See example program at: sorting.c Insertion sort with commandline input Functions for ascending or descending order are passed as parameters to the insertion sort function Note the error checking at the beginning of the program We don’t want our programs to crash!