C-WS4-ArraysAndPointers Flashcards

1
Q

K1 Word

A

ANSI Standard size of type int (4 bytes)

unit of data that can be addressed and moved between storage and computer processer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

K2 Environment Variables

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

K3 Main arguments(argc, argv, envp)

A

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=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

K4 Array

A

stores fixed-size sequential collection of elements of the same type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

K5 sizeof

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q1 What is a word? what does it represent?

A

represents the standard size of type int (4 bytes),

unit of data that can be addressed and moved between storage and computer processer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q2 given the following piece of code, answer the questions below:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q3 which lines of code below are possible? which are not? why?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly