1. In C arrays and pointers can always be used interchangeably.

2. In C, a string is equivalent to a pointer to a character.

3. In C, an array with ten elements is indexed from 1 through 10.

4. If str is a character pointer variable that holds the string "Read SparkNotes", then str[3] refers to the character 'a'.

5. In C, when an array is passed to a function, only the address of the array is passed to the function.

6. In C, a parameter is passed by reference when the address of a variable is passed to the function.

7. The declaration typedef int *i_ptr; creates a variable called i_ptr which can hold the addresses of integers.

8. The function malloc can be used to dynamically allocate memory for an array.

9. If rec is a struct variable and number is a field of the structure, then the number field of rec is expressed as rec->number.

10. Let p be a pointer to an integer and i be an integer variable. Which of the following is not a correct assignment?

11. In C, the end of a string is marked by

12. A segmentation fault occurs when:

13. The expression sizeof(int) refers to

14. What is the output of the following program?
int main () { int i, j, *p, *q; p = &i; q = &j; *p = 5; *q = *p + i; printf("i = %d, j = %d\n", i, j); return 0; }

15. What is the output of the following program?
void spark(int A[]) { printf("A[0] = %d, A[1] = %d, A[2] = %d\n", A[0], A[1], A[2]); A[1] = 0; } int main() { int A[3] = {1, 2, 3}; spark(A); printf("A[0] = %d, A[1] = %d, A[2] = %d\n", A[0], A[1], A[2]); return 0; }

16. What is the output of the following program?
void add_10(int a, int *p) { *p = a + 10; } int main() { int x = 2, y = 6; add_10 (x, &x) ; printf("x = %d, y = %d\n", x, y) ; add_10 (x, &y) ; printf("x = %d, y = %d\n", x, y) ; return 0; }

17. In most languages and on most computer systems, NULL is what value?

18. int *x; and int* x; both have the same effect.

19. Functions aren't basic data types, so you can't have pointers to them.

20. A memory leak happens when we allocate memory using malloc() and then free it using free().

21. What does the following function do?
void mystery(int* a, int* b) { if (*a > *b) { int temp = *a; *a = *b; *b = temp; } }

22. A dangling pointer is a pointer which points to a thing in memory which has been free'd or has vanished for some other reason. Dangling pointers are bad because you don't know what's at that spot any longer. In the following code, what is the dangling pointer?
int* y = malloc(sizeof(int)); int* z = y; free(z);

23. Two or more memory locations can have the same address.

24. A pointer variable can point to floating-point values only.

25. An array can be used as a constant pointer.

26. Pointers can store the addresses of which data structures?

27. What is the name of the & operator?

28. Which of the following is not a use of the * operator?

29. In the following code
int spark; int *p; p = &spark; p += 2;
the variable spark is stored at memory address 0x1234, and sizeof(int) == 4. What is the value of p at the end of this code segment?

30. Which of the following are equivalent, assuming that arr is an integer array and that ptr is an integer pointer pointing to the start of the array?

31. What data structure, in words, does the following declaration declare? float * measures[250];

32. Given the following variable and array declarations
float arr[] = {1.0, 2.1, 3.2, 4.3, 5.4, 6.5, 7.6, 8.7}; float * ptr1, *ptr2;
which of the following assignments is not allowed?

33. What does the variable i contain after the following code executes?
int i = 17; int *p = &i; *p = 98;

34. What, if anything, is wrong with the following code?
void *p; p = (float*) malloc(sizeof(float)); *p = 7.89;

35. After the following code:
int *p; int i; int k; i = 63; k = i; p = &i;
which of the following statements will change the value of i to 2105?

36. After the following code:
int i = 23; int j = 72; int *p1; int *p2; p1 = &i; p2 = &j; *p1 = *p2;
what are the values of i and j, respectively?

37. After the following code:
int i = 2; int k = 4; int *p1; int *p2; p1 = &i; p2 = &k; p1 = p2; *p1 = 6; *p2 = 8;
what is the value of i?

38. After the following code:
int i = 2; int k = 4; int *p1; int *p2; p1 = &i; p2 = &k; p1 = p2; *p1 = 6; *p2 = 8;
what is the value of k?

39. After the following code:
int i = 2; int k = 4; int* p1; int* p2; p1 = &i; p2 = &k; *p1 = *p2; *p1 = 6; *p2 = 8;
what is the value of i?

40. Given the following array declaration and function definition
void spark(int z[]); int x[10];
how would you call the spark function with x as an argument?

41. Given the following array declaration and function definition
void spark(int z[]); int x[10];
suppose that spark() changes the value of z[1]. Is x[1] affected?

42. After this code executes
int arr[10]; int i; i = &arr[9] - arr;
what is the value of i?

43. In a C/C++ program, the main() function is actually defined as int main(int argc, char **argv); What is argv?

44. What is 0xabcd in binary?

45. In the following code
int a = 54; int *p = (int *)malloc(1); *p = 72; p = &a;
which of the following is NOT a possible problem?

Popular pages: Review of Pointers