C-WS4-ArraysAndPointers Flashcards
K1 Word
ANSI Standard size of type int (4 bytes)
unit of data that can be addressed and moved between storage and computer processer
K2 Environment Variables
define the characteristics of a specific environment
can be inherited from system definitions, yet modified at an application level without affecting the environment of other applications or the system settings
K3 Main arguments(argc, argv, envp)
int argc (number of command line arguments argv[] holds for this current program’s execution)
char ** arg (aka, char * argv[], pointer to the list of actual const string arguments)
char ** envp (char * envp[], holds environment variables as string constants, plus the header: PATH=)
argc: instructions to command line,
argv: pointer to arguments given to main
envp: holds env variables as string constants, please header PATH=
K4 Array
stores fixed-size sequential collection of elements of the same type
K5 sizeof
computes the size of it operand.
printf(“%lu\n”, sizeof(char)); //1
printf(“%lu\n”, sizeof(int)); //4
printf(“%lu\n”, sizeof(float)); //4
printf(“%lu”, sizeof(double)); //8
Q1 What is a word? what does it represent?
represents the standard size of type int (4 bytes),
unit of data that can be addressed and moved between storage and computer processer
Q2 given the following piece of code, answer the questions below:
a) sizeof(str): == 8, strlen(str)==7, the string itself is 7 characters long, but its size includes the escape character \0
b) sizeof(arr) == 40, sizeof(a)==8, the size of the array is 10 elements of size it (4 bytes), therefore 4*10=40, array decays to a pointer when passed as a variable. on 64-bit system, that’s 8 bytes. or 4 bytes on 32 bit system
Q3 which lines of code below are possible? which are not? why?
char* p = “lalala”;
char arr[10] = “lalala”;
\++p; /*++arr; arr is not a character pointer. won't compile.*/ /* *p = 's'; *//*causes a segmentation fault*/ /*p[0] = 's';*//*causes segmentation fault*/ arr[1] = 's'; *(arr + 1) = 's'; 1[arr] = 's';
p allocation: x616x616c sizeof: 8, multidimensional vs **
arr allocation: x616x616c sizeof: 10, multidimensional