You are on page 1of 5

what is (void*)0?

A. Representation of NULL pointer


B. Representation of void pointer
C. Error
D. None of above
ANSWER: A
Can you combine the following two statements into one?char *p;p = (char*) malloc
(100);
A. char p = *malloc(100);
B. char *p = (char) malloc(100);
C. char *p = (char*)malloc(100);
D. char *p = (char *)(malloc*)(100);
ANSWER: C
In which header file is the NULL macro defined?
A. stdio.h
B. stddef.h
C. stdio.h and stddef.h
D. math.h
ANSWER: C
If a variable is a pointer to a structure, then which of the following operator
is used to access data members of the structure through the pointer variable?
A. .
B. &
C. *
D. ->
ANSWER: D
A pointer is
A. A keyword used to create variables
B. A variable that stores address of an instruction
C. A variable that stores address of other variable
D. All of the above
ANSWER: D
The operator used to get value at address stored in a pointer variable is
A. *
B. &
C. &&
D. ||
ANSWER: A
#include<stdio.h>int main(){int *x;*x=100;return 0;}
A. Error: invalid assignment for x
B. Error: suspicious pointer conversion
C. No error
D. None of above
ANSWER: c
Are the expression *ptr++ and ++*ptr are same?
A. True B. False
ANSWER: B
The following program reports an error on compilation.#include<stdio.h>int main(
){float i=10, *j;void *k;k=&i;j=k;printf("%f\n", *j);return 0;}
A. True B. False
ANSWER: B
Which of the statements is correct about the program?#include<stdio.h>int main()
{int i=10;int *j=&i;return 0;}
A.
j and i are pointers to an int
B.
i is a pointer to an int and stores address of j
C.
j is a pointer to an int and stores address of i
D.
j is a pointer to a pointer to an int and stores address of i
ANSWER: C
In the following program add a statement in the function fun() such that address
of a gets stored in j?#include<stdio.h>int main(){int *j;void fun(int**);fun(&j

);return 0;}voidfun(int **k){int a=10;/* Add a statement here */}


A. **k=a;
B. k=&a;
C. *k=&a
D. &k=*a
ANSWER: C
What will be output of following program?#include<stdio.h>int main(){int a = 10;
void *p = &a;int *ptr = p;printf("%u",*ptr);return 0;}
A. 10
B. Address
C. 2
D. Compilation error
ANSWER: A
What will be output of following program?#include<stdio.h>#include<string.h>int
main(){int a = 5,b = 10,c;int *p = &a,*q = &b;c = p - q;printf("%d" , c);return
0;}
A. 1
B. 5
C. -5
D. Compilation error
ANSWER: A
What is meaning of following declaration?int(*ptr[5])();
A. ptr is pointer to function.
B. ptr is array of pointer to function.
C. ptr is pointer to such function which return type is array.
D. ptr is pointer to array of function.
ANSWER: B
What is meaning of following pointer declaration?int(*(*ptr1)())[2];
A. ptr is pointer to function.
B. ptr is array of pointer to function.
C. ptr is pointer to such function which return type is pointer to an array.
D. ptr is pointer array of function.
ANSWER: C
What will be output if you will compile and execute the following c code?#includ
e<stdio.h>int main(){int a=5,b=10,c=15;int *arr[]={&a,&b,&c};printf("%d",*arr[1]
);return 0;}
A. 5
B. 10
C. 15
D. Compiler error
ANSWER: D
What will be output if you will compile and execute the following c code?#includ
e<stdio.h>int main(){int a[2][4]={3,6,9,12,15,18,21,24};printf("%d %d %d",*(a[1]
+2),*(*(a+1)+2),2[1[a]]);return 0;}
A. 15 18 21
B. 21 21 21
C. 24 24 24
D. Compiler error
ANSWER: B
What is the output of this C code?#include <stdio.h>void main(){char *s= "hello"
;char *p = s;printf("%c\t%c", *(p + 3), s[1]);}
A. h e
B. l l
C. l o
D. l e
ANSWER: D
What is the output of the code given below?#include <stdio.h>int main(){int ary[
4] = {1, 2, 3, 4};int *p = ary + 3;printf("%d %d\n", p[-2], ary[*p]);}
A. 2 3
B. Compile time error

C. 2 4
D. 2 somegarbagevalue
ANSWER: D
Which of the following is not possible in C?
A. Array of function pointer
B. Returning a function pointer
C. Comparison of function pointer
D. None of the mentioned
ANSWER: D
What is the output of this C code?#include <stdio.h>void main(){int k = 5;int *p
= &k;int **m = &p;printf("%d%d%d\n", k, *p, **p);}
A. 5 5 5
B. 5 5 junk value
C. 5 junk junk
D. Compile time error
ANSWER: D
How many number of pointer (*) does C have against a pointer variable declaratio
n?
A. 7
B. 127
C. No limits
D. 255.
ANSWER: C
What is the output of this C code?#include <stdio.h>struct p{int x;int y;};int m
ain(){struct p p1[] = {1, 2, 3, 4, 5, 6};struct p *ptr1 = p1;printf("%d %d\n", p
tr1->x, (ptr1 + 2)->x);}
A. 1 5
B. 1 3
C. Compile time error
D. 1 4
ANSWER: A
Determine Output:main(){char *str1 = "abcd";char str2[] = "abcd";printf("%d %d %
d", sizeof(str1), sizeof(str2), sizeof("abcd"));}
A. 255
B. 244
C. 555
D. 245
ANSWER: A
Choose the best answer.Prior to using a pointer variable
A. It should be declared.
B. It should be initialized.
C. It should be both declared and initialized.
D. None of these.
ANSWER: C
Comment on the following pointer declaration?int *ptr, p;
A. ptr is a pointer to integer, p is not.
B. ptr and p, both are pointers to integer.
C. ptr is pointer to integer, p may or may not be.
D. ptr and p both are not pointers to integer.
ANSWER: A
The statement int **a;
A. is illegal
B. is legal but meaningless
C. is syntactically and semantically correct
D. None of these.
ANSWER: C
The operator > and < are meaningful when used with pointers, if
A. The pointers point to data of similar type.
B. The pointers point to structure of similar data type.
C. The pointers point to elements of the same array.

D. None of these.
ANSWER: C
The declaration int (*p) [5];means
A. p is one dimensional array of size 5, of pointers to integers.
B. p is a pointer to a 5 elements integer array.
C. The same as int *p[
D. None of these.
ANSWER: B
Which of the following is the correct way of declaring a float pointer:
A. float ptr;
B. float *ptr;
C. *float ptr;
D. None of the above
ANSWER: B
Find the output of the following program.void main(){printf("%d, %d", sizeof(int
*), sizeof(int **));}
A. 2, 0
B. 0, 2
C. 2, 2
D. 2, 4
ANSWER: C
Which of the following statements are true after execution of the program.void m
ain(){int a[10], i, *p;a[0] = 1;a[1] = 2;p = a;(*p)++;}
A. a[1] = 3
B. a[0] = 2
C. a[1] = 2
D. a[0] = 3
ANSWER: B
What is the base data type of a pointer variable by which the memory would be al
located to it?
A. int
B. unsigned int
C. No data type
D. Depends upon the type of the variable to which it is pointing.
ANSWER: B
What would be the output for the following Turbo C code?#include<stdioh>void mai
n(){int a[]={ 1, 2, 3, 4, 5 }, *p;p=a;++*p;printf("%d ", *p);p += 2;printf("%d",
*p);}
A. 2 4
B. 3 4
C. 2 2
D. 2 3
ANSWER: D
char *ptr;char myString[] = "abcdefg";ptr = myString;ptr += 5;what string does p
tr point to in the sample code above?
A. fg
B. efg
C. defg
D. cdefg
ANSWER: A
What is the output of this C code?int main(){int i = 10;void *p = &i;printf("%d\
n", (int)*p);return 0;}
A. Compile time error
B. Segmentation fault/runtime crash
C. 10
D. Undefined behaviour
ANSWER: A
What is the output of this C code?int *f();int main(){int *p = f();printf("%d\n"
, *p);}int *f(){int *j = (int*)malloc(sizeof(int));*j = 10;return j;}
A. 10

B. Compile time error


C. Segmentation fault/runtime crash since pointer to local variable is returned
D. Undefined behaviour
ANSWER: A
What is the output of this C code?int main(){int *ptr, a = 10;ptr = &a;*ptr += 1
;printf("%d,%d/n", *ptr, a);}
A. 10,10
B. 10,11
C. 11,10
D. 11,11
ANSWER: D
Comment on the following?const int *ptr;
A. You cannot change the value pointed by ptr
B. You cannot change the pointer ptr itself
C. Both (a) and (b)
D. You can change the pointer as well as the value pointed by it
ANSWER: A
What is the output of this C code?void main(){int x = 0;int *ptr = &5;printf("%p
\n", ptr);}
A. 5
B. Address of 5
C. Nothing
D. Compile time error
ANSWER: D

You might also like