Download as TXT, PDF, TXT or read online from Scribd
Download as txt, pdf, or txt
You are on page 1of 3
A pointer is a
A) variable that stores address of an instruction
B) variable that stores address of other variable C) keyword used to create variables D) None of these ANSWER: B Faster access to non-local variables is achieved using an array of pointers to activation records, called a A) stack B) heap C) display D) activation tree ANSWER: D How can you write a[i][j][k][l] in an equivalent pointer expression? A) (((***(a+i)+j)+k)+l) B) ((**(*(a+i)+j)+k)+l) C) (*(*(*(a+i)+j)+k)+l) D) *(*(*(*(a+i)+j)+k)+l) ANSWER: D Pick the best statement for the following program snippet: #include <stdio.h>int main(){ int var; /*Suppose address of var is 2000 */ void *ptr = &var; *ptr = 5; printf("var=%d and *ptr=%d",var,*ptr); return 0;} A) It will print “var=5 and *ptr=2000” B) It will print “var=5 and *ptr=5” C) It will print “var=5 and *ptr=XYZ” where XYZ is some random address D) Compile error ANSWER: D The following statement in ‘C’int (*f())[ ]; declares A) a function returning a pointer to an array of integers. B) a function returning an array of pointers to integers. C) array of functions returning pointers to integers. D) an illegal statement. ANSWER: A Consider the following declaration:int a, *b=&a, **c=&b;The following program fragmenta=4;**c=5; A) does not change the value of a B) assigns address of c to a C) assigns the value of b to a D) assigns 5 to a ANSWER: D What is the output of this C code?#include<stdio.>void main() { int k=5; int *p=&k; int **m=&p; printf("%d %d %d",k,*p,**m);} A) 5 5 5 B) 5 5 junk C) 5 junk junk D) Compile time error ANSWER: A What is printed by the following ANSI C program? #include<stdio.h> int main(int argc, char *argv[]) { int x = 1, z[2] = {10, 11}; int *p = NULL; p = &x; *p = 10; p = &z[1]; *(&z[0] + 1) += 3; printf("%d, %d, %dn", x, z[0], z[1]); return 0; } A) 1, 10, 11 B) 1, 10, 14 C) 10, 14, 11 D) 10, 10, 14 ANSWER: D Consider the following C program.#include<stdio.h>void mystery(int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb = ptra; ptra = temp;}int main() { int a=2016, b=0, c=4, d=42; mystery(&a, &b); if (a < c) mystery(&c, &a); mystery(&a, &d); printf ("%d", a);}The output of the program _____________ . A) 2016 B) 0 C) 4 D) 8 ANSWER: A If ptr is a pointer to int, having value ptr=100. After ptr++, what is the value of ptr? A) 100 B) 101 C) 102 D) 103 ANSWER: C The value printed by the following program isvoid f(int* p, int m) { m = m + 5; *p = *p + m; return;}void main(){ int i=5, j=10; f(&i, j); printf("%d", i+j);} A) 10 B) 20 C) 30 D) 40 ANSWER: C Consider the C program below. What does it print? #include <stdio.h>#define swapl(a, b) tmp = a; a = b; b = tmpvoid swap2(int a, int b){ int tmp; tmp = a; a = b; b = tmp;}void swap3(int*a, int*b){ int tmp ; tmp = *a; *a = *b; *b = tmp;}int main (){ int num1 = 5, num2 = 4, tmp; if (num1 < num2) {swap1 (num1, num2);} if (num1 < num2) {swap2 (num1 + 1, n um2);} if (num1 >= num2) {swap3 (&num1, &num2);} printf ("%d, %d", num1, num2);} A) 5, 5 B) 5, 4 C) 4, 5 D) 4, 4 ANSWER: C What will be the output produced by the following C code:int main() { int array[5][5]; printf("%d",( (array == *array) && (*array == array[0]) )) ; return 0; } A) 1 B) 0 C) 2 D) -1 ANSWER: A Consider the following C codeint main() { int a = 300; char *b = (char *)&a; *++b = 2; printf("%d ",a); retur n 0;}Consider the size of int as two bytes and size of char as one byte. Predict the output of the following code . Assume that the machine is little-endian. A) 556 B) 300 C) Run Time Error D) Compile Time Error ANSWER: A Consider the following function implemented in C:void printxy(int x, int y) { int *ptr; x = 0; ptr = &x; y = *ptr; *ptr = 1; printf("%d,%d", x, y);}The output of the printxy(1,1) is A) 0,0 B) 0,1 C) 1,0 D) 1,1 ANSWER: C Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.int main() { int array[] = {3, 5, 1, 4, 6, 2}; int done = 0; int i; while (done == 0) { done = 1; for (i = 0; i <= 4; i++) { if (a rray[i] < array[i+1]) { swap(&array[i], &array[i+1]); done = 0; } } for (i = 5; i >= 1; i--) { if (array[i] > array[i-1]) { swap(&array[i], & array[i-1]); done = 0; } } } printf("%d", ar ray[3]);}The output of the program is ________. A) 1 B) 2 C) 3 D) 4 ANSWER: C The following ‘C’ statement: int * f [ ] ( ); declares: A) A function returning a pointer to an array of integers. B) Array of functions returning pointers to integers. C) A function returning an array of pointers to integers. D) An illegal statement. ANSWER: B The reason for using pointers in a C program is A) Pointers allow different functions to share and modify their local variables. B) To pass large structures so that complete copy of the structure can be avoided. C) Pointers enable complex “linked" data structures like linked lists and binary trees. D) All of the above ANSWER: D What does the following C-statement declare?int (*f) (int*); A) A function that takes an integer pointer as argument and returns an integer B) A function that takes an integer as argument and returns an integer pointer C) A pointer to a function that takes an integer pointer as argument and returns an integer D) A function that takes an integer pointer as argument and returns a function pointer ANSWER: C ‘PTRDATA’ is a pointer to a data type. The expression *PTRDATA++ is evaluated as (in C) : A) Depends on compiler B) (*ptrdata)++ C) *(ptrdata)++ D) *(ptrdata++) ANSWER: D