What will be the output of the following C code? #include <stdio.h> int main() { char *p = NULL; char *q = 0; if (p) printf(" p "); else printf("nullp"); if (q) printf("q\n"); else printf(" nullq\n"); }
nullp nullq
Depends on the compiler
x nullq where x can be p or nullp depending on the value of NULL
p q
What will be the output of the following C code?
#include <stdio.h> int main() { int i = 10; void *p = &i; printf("%d\n", (int)*p); return 0; }
Compile time error
Segmentation fault/runtime crash
10
Undefined behaviour
What will be the output of the following C code?
#include <stdio.h> int main() { int i = 10; void *p = &i; printf("%f\n", *(float*)p); return 0; }
Compile time error
Undefined behaviour
10
0.000000
What will be the output of the following C code? #include <stdio.h> int *f(); int main() { int *p = f(); printf("%d\n", *p); } int *f() { int *j = (int*)malloc(sizeof(int)); *j = 10; return j; }
10
Compile time error
Segmentation fault/runtime crash since pointer to local variable is returned
Undefined behaviour
What will be the output of the following C code?
#include <stdio.h> int *f(); int main() { int *p = f(); printf("%d\n", *p); } int *f() { int j = 10; return &j; }
10
Compile time error
Segmentation fault/runtime crash
Undefined behaviour
Comment on the following pointer declaration.
int *ptr, p;
ptr is a pointer to integer, p is not
ptr and p, both are pointers to integer
ptr is a pointer to integer, p may or may not be
ptr and p both are not pointers to integer
What will be the output of the following C code?
#include <stdio.h> int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d,%d/n", *ptr, a); }
10,10
10,11
11,10
11,11
Comment on the following C statement.
const int *ptr;
You cannot change the value pointed by ptr
You cannot change the pointer ptr itself
You May or may not change the value pointed by ptr
You can change the pointer as well as the value pointed by it
Which is an indirection operator among the following?
&
*
->
.
Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;)?
int *ptr = &a;
int *ptr = &a – &a;
int *ptr = a – a;
All of the mentioned
What will be the output of the following C code?
#include <stdio.h> int x = 0; void main() { int *ptr = &x; printf("%p\n", ptr); x++; printf("%p\n ", ptr); }
Same address
Different address
Compile time error
Varies
What will be the output of the following C code?
#include <stdio.h> int x = 0; void main() { int *const ptr = &x; printf("%p\n", ptr); ptr++; printf("%p\n ", ptr); }
0 1
Compile time error
0xbfd605e8 0xbfd605ec
0xbfd605e8 0xbfd605e8
What will be the output of the following C code?
#include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%p\n", ptr); ptr++; printf("%p\n ", ptr); }
0xbfd605e8 0xbfd605ec
0xbfd605e8 0cbfd60520
0xbfd605e8 0xbfd605e9
Run time error
What will be the output of the following C code?
#include <stdio.h> void main() { int x = 0; int *ptr = &5; printf("%p\n", ptr); }
5
Address of 5
Nothing
Compile time error
What will be the output of the following C code? #include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%d\n", *ptr); }
Address of x
Junk value
0
Run time error
What will be the output of the following C code? #include <stdio.h> void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d\n", k, *p, **m); }
5 5 5
5 5 junk value
5 junk junk
Run time error
What will be the output of the following C code?
#include <stdio.h> void main() { int k = 5; int *p = &k; int **m = &p; **m = 6; printf("%d\n", k); }
5
Compile time error
6
junk
What will be the output of the following C code? #include <stdio.h> void main() { int a[3] = {1, 2, 3}; int *p = a; int *r = &p; printf("%d", (**r)); }
1
Compile time error
Address of a
Junk value
What will be the output of the following C code?
#include <stdio.h> void main() { int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); }
Different address is printed
1 2
Same address is printed
1 1
How many number of pointer (*) does C have against a pointer variable declaration?
7
127
255
No limits
What will be the output of the following C code?
#include <stdio.h> int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c; int **sptr = &ptr1; //-Ref *sptr = ptr2; }
ptr1 points to a
ptr1 points to b
sptr points to ptr2
none of the mentioned
What will be the output of the following C code?
#include <stdio.h> void main() { int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); }
Different address is printed
1 2
Same address is printed
1 1
What substitution should be made to //-Ref such that ptr1 points to variable c in the following C code? #include <stdio.h> int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a; int **sptr = &ptr1; //-Ref }
*sptr = &c;
**sptr = &c;
*ptr1 = &c;
none of the mentioned
Which of the following declaration will result in run-time error?
int **c = &c;
int **c = &*c;
int **c = **c;
none of the mentioned
Comment on the output of the following C code. #include <stdio.h> int main() { int a = 10; int **c -= &&a; }
You cannot apply any arithmetic operand to a pointer
We don’t have address of an address operator
We have address of an address operator
None of the mentioned
What will be the output of the following C code?
#include <stdio.h> void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d\n", k, *p, **m); }