Coding Interview Questions For Round 1
Coding Interview Questions For Round 1
Coding Interview Questions For Round 1
1)
#include "stdio.h"
int main()
int _ = 5;
int __ = 10;
int ___;
___ = _ + __;
printf("%i", ___);
return 0;
(A) 5
(B) 10
(C) 15
Answer : 15
2)
main()
int i;
for(i=9;i;i=i-2)
printf("\n%d",i);
}
}
(A) 5
(B) 6
(D) Infinite
Answer : Infinite
3)
main()
int a,b,c;
a=10;
b=20;
c=printf("%d",a)+ ++b;
printf("\n%d",c);
(A) 23
(B) 22
(C) 30
Answer : 23 //a=10(no of digit in a) so 2;//2+(21)=23;// If there is any (\t,\n escape sequence )also
get 1;
4)
main ()
{
int i, j, k;
i = 3;
(A) j = 6, k = 10.
(B) i = 5, k = 6.
(C) j = 6, k = 8.
(D) i = 4, j = 6.
Answer : j = 6, k = 10.
5)
main()
{
int x=5;
printf("%d,%d,%d",x,x<<2,x>>2); //left shift= remove 2 digits left and add 2 0s to right (x*2^y)
(A) 5,21,1
(B) 5,20,1
(C) 5,19,0
(D) 5,19,1
Answer : 5,20,1
6)
void main(){
int a=80;
if(a++>80) // a=80 next line a=81;
printf("welcome%d",a);
else
printf("hello%d",a); //a=81
(A) hello 81
(B) welcome 81
(C) hello 80
(D) welcome 80
Answer : hello 81
7)
void main(){
float a;
a=6.7;
printf("A");
else
printf("B");
(A) A
(B) B
(C) error
Answer : B
8)
what is the output of following program?
void main(){
int a;
a=1;
while(a-->=0);
printf("%d",a);
(A) 3
(B) -3
(C) 0
(D) error
Answer : -3
9)
void main(){
int a=1;
printf("%d",a);
printf("%d%d",x,y);
(A) 3 1 3 4 5
(B) 3 1 4 4 5
(C) 3 1 4 4 4
(D) 3 1 4 5 5
Answer : 3 1 4 4 5
10)
main ( )
int a = 1 ;
(A) 100
(B) 1
(C) 0
(D) Infinite
Answer : Infinite
11)
void main(){
int a;
a=10;
while(a++<=15)
printf("%d",a);
printf("%d",a+10);
(A) 10 11 12 13 14 15 16
(B) 11 12 13 14 15 16 27
(C) 10 11 12 13 14 15 25
(D) 11 11 12 13 14 15 25
Answer : 11 12 13 14 15 16 27
12)
++p1;
++*p2;
printf("%d%d",p1,*p2);
void main(){
int a=10;
xyz(a++,++*(&a));
xyz(a++,++*(&a));
printf("%d",a);
(A) 10 11 13 14 14
(B) 11 12 14 15 15
(C) 12 13 15 16 16
(D) 11 12 13 14 14
Answer : 12 13 15 16 16
13)
What is the output of the following program?
void main(){
int a,b;
a=b=10;
while(a)
a=b++<=13;
printf("%d%d",a,b);
printf("%d%d",a+10,b+10);
14)
void main(){
int a;
a=1;
a++ * ++a;
printf("%d",a);
(A) 3
(B) 4
(C) 6
(D) 2
Answer : 3
15)
void main(){
int a,b;
a=b=1;
a=a++ + ++b;
b=b++ + ++a;
printf("%d%d",a,b);
`(A) 4 7
(B) 5 7
(C) 4 8
(D) 4 6
Answer : 4 6
16)
++p1;
++*p2;
printf("%d%d",p1,*p2);
void main(){
int a=10;
xyz(a++,&a);
xyz(a++,&a);
printf("%d",a);
(A) 10 11 12 13 13
(B) 11 12 13 13 14
(C) 10 11 12 12 13
(D) 11 12 13 14 14
Answer : 11 12 13 14 14
17)
void main(){
int a=1;
while(a++<=1)
while(a++<=2);
printf("%d",a);
(A) 2
(B) 3
(C) 4
(D) 5
Answer : 5
18)
void main(){
int a;
a=1;
while(a<=1)
if(a%2)
printf("%d",a++);
printf("%d",a+10);
(A) 2 11
(B) 1 11
(C) 2 12
(D) 1 12
Answer : 1 12
19)
main( )
{
int i, *ptr ;
ptr = pskills;
{
fun(ptr++);
}
}
{
*i = *i + 1;
}
(A) 11 21 31 41
(B) 20 30 40 50
(C) 21 31 41 51
(D) 10 20 30 40
Answer : 20 30 40 50
void main(){
int a=2;
switch(a)
case 1: printf("A");
break;
case 2: printf("B");
case 3: printf("C");
break;
case 4; printf("D");
default: printf("E");
Answer : error
21)
void main(){
int a=2;
{
case 1: printf("A");
case 2: printf("B");
case 3: printf("C");
break;
case 4: printf("D");
default: printf("E");
break;
Answer : error
22)
void main(){
int a=2;
switch(a)
break;
case3: printf("B");
case2: printf("C");
case1: printf("D");
break;
default: printf("E");
}
Answer : E
23)
void main(){
int a=2;
switch(a)
case 4: printf("A");
break;
case 3: printf("B");
case 1 : printf("D");
break;
case 5 : printf("E");
Answer : error
void f1(){
extern int g;
int a;
++g;
a=s++;
printf("%d%d%d",a,s,g);
if(a<=6)
f1();
printf("%d%d%d",a,s,g);
void f2(){
static int s;
int a;
a=++s;
printf("%d%d%d",a,s,g);
if(a<=2)
f2();
printf("%d%d%d",a,s,g);
main(){
f1();
f2();
Answer : error
25)
void main(){
int a;
a=1;
while(a<=10){
printf("%d",a);
if(a>3)
break;
a++;
}
printf("%d",a+10);
Answer : 1 2 3 4 14
1.ques:
2.A long double can be used if range of a double is not enough to accommodate a real number
1.Ans : TRUE
2.ques:Is there any difference in the #define and typedef in the following code?
2.ANS : YES
3.ANS : TRUE
4.ANS : TRUE
5.ANS : NO
6.#include<stdio.h>
int main()
int c;
c = check(10, 20);
printf("c=%d\n", c);
return 0;
p=&i;
q=&j;
#include<stdio.h>
int main()
printf("IndiaBIX");
main();
return 0;
A.Infinite times
B.32767 times
C.65535 times
int (*pf)();
B.pf is a function.
9.ANS : YES.
10.#include<stdio.h>
int main()
char *p;
p="%d\n";
p++;
p++;
printf(p-2, 23);
return 0;
A.21
B.23
C.Error
D.No output
10.ANS : 23
11.What will be the output of the program if the size of pointer is 4-bytes?
#include<stdio.h>
int main()
return 0;
}
A.2, 1
B.2, 2
C.4, 1
D.4, 2
ANS : 4,1
12.#include<stdio.h>
int main()
*p='M';
printf("%s\n", str);
return 0;
A.Mello
B.Hello
C.HMello
D.MHello
12.ANS : Mello
1:
struct aa
{
int a;
float b;
};
2:
struct aa
int a;
float b;
struct aa var;
};
3:
struct aa
int a;
float b;
struct aa *var;
};
A.1
B.2
C.3
D.1, 2, 3
14.ANS : b.2
15.Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2.
A.True
B.False
15.ANS : TRUE
16.Bitwise & can be used to check if more than one bit in a number is on.
A.True
B.False
16.ANS:TRUE
17.Which of the following is correct way to define the function fun() in the below program?
#include<stdio.h>
int main()
int a[3][4];
fun(a);
return 0;
A.
{
}
B.
C.
D.
17.ANS : A
capps.txt
#include <stdio.h>
int main()
{
int i = 10;
foo(&p);
printf("%d\n", *p);
}
{
int j = 11;
*p = &j;
printf("%d\n", **p);
}
a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
9. Which of the following is the correct syntax to send an array as a parameter to function?
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);
11. Which type of variables can have same name in different function?
a) global variables
b) static variables
c) Function arguments
d) Both static variables and Function arguments
12. Arguments that take input by user before running a program are called?
a) main function arguments
b) main arguments
c) Command-Line arguments
d) Parameterized arguments
13. What is the maximum number of arguments that can be passed in a single function?
a) 127
b) 253
c) 361
d) No limits in number of arguments
#include <stdio.h>
{
}
void main()
{
int a = 6, b = 5;
m(&a, &b);
}
a) 5 6
b) 6 5
c) 5 5
d) 6 6
#include <stdio.h>
{
int i = 0;
for(i = 0;i < 5; i++)
printf("%d\t", p[i]);
}
void main()
{
m(&a);
}
a) 0 0 0 0 0
b) 6 5 3 0 0
c) Run time error
d) 6 5 3 junk junk
{
int temp = p;
p = q;
q = temp;
}
void main()
{
int a = 6, b = 5;
m(a, b);
}
a) 5 6
b) 5 5
c) 6 5
d) 6 6
#include <stdio.h>
{
}
void main()
{
int a = 6, b = 5;
m(a);
}
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
#include <stdio.h>
void m(int p)
{
printf("%d\n", p);
}
void main()
{
int a = 6, b = 5;
m(a, b);
}
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
#include <stdio.h>
void main()
{
int *p = a;
printf("%p\t%p", p, a);
}
20. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *s = "hello";
char *p = s;
printf("%p\t%p", p, s);
}
void main()
{
char *p = s;
}
#include <stdio.h>
void main()
{
char *p = s;
}
a) h e
b) l l
c) l o
d) l e
#include <stdio.h>
void main()
{
char *p = s;
}
a) h h
b) Run time error
c) l l
d) e e
24. What will be the output of the following C code?
#include <stdio.h>
int main()
{
foo(ary);
}
int i = 10;
p = &i;
}
a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
#include <stdio.h>
int main()
{
printf("%d\n", p[-2]);
}
a) 1
b) 2
c) Compile time error
d) Some garbage value
#include
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer: 77
#include
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
Answer:
Compiler Error
#include
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
Answer:
Compiler Error
Answer:
64
main()
{
printf("%p",main);
}
Answer:
Some address will be printed.
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
Answer:
Linker error: undefined symbol '_i'.
A. stdio.h
B. stddef.h
D. math.h
Answer : c
A. 30
B. 27
C. 9
D. 3
Answer : a
#include<stdio.h>
int i;
int main()
void *vptr;
vptr = &i;
fun(vptr);
return 0;
int **q;
q = (int**)&p;
printf("%d\n", **q);
B. Garbage value
C. 0
D. No output
Answer : c
#include<stdio.h>
int main()
char *str;
str = "%s";
printf(str, "K\n");
return 0;
A. Error
B. No output
C. K
D. %s
Answer : Option C
#include<stdio.h>
int main()
int *c;
c = check(10, 20);
printf("%d\n", c);
return 0;
p = &i;
q = &j;
return (p);
else
return (q);
A. 10
B. 20
Answer : d
12. What will be the output of the program if the size of pointer is 4-bytes?
#include<stdio.h>
int main()
return 0;
}
A. 2, 1
B. 2, 2
C. 4, 1
D. 4, 2
Answer : Option C
#include<stdio.h>
int main()
void *vp;
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c", *(int*)vp);
vp=cp;
printf("%s", (char*)vp+2);
return 0;
}
A. JCK
B. J65K
C. JAK
D. JACK
Answer : Option D
#include <stdio.h>
int main()
int *p = ary + 3;
a) 2 3
c) 2 4
d) 2 somegarbagevalue
ANSWER: d
#include <stdio.h>
int main()
{
int *p;
p = ary + 3;
*p = 5;
printf("%d\n", ary[3]);
a) 4
b) 5
d) 3
ANSWER : b
#include <stdio.h>
#define MAX 10
int main()
int array[MAX]={1,2,3},tally;
for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)
printf("%d ",*(tally+array));
return 0;
1. Error
2. 1 3 4 5 6 7 8 9 10 11
3. 1 2 3 0 0 0 0 0 0 0
4. 0 0 0 0 0 0 0 0 0 0
ANSWER : 3
#include<stdio.h>
int main()
char *s = str;
return 0;
A. peace
B. eace
C. ace
D. ce
Answer : Option D
#include<stdio.h>
power(int**);
int main()
{
aa = &a;
a = power(&aa);
printf("%d\n", a);
return 0;
power(int **ptr)
int b;
b = **ptr***ptr;
return (b);
A. 5
B. 25
C. 125
D. Garbage value
Answer : Option B
main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
Answer:
255
20. What is the output generated on execution of the following C Program?
#include<stdio.h>
int main()
{
{
float sal;
};
return 0;
Ans : o , o.oooooo
#include<stdio.h>
int main()
i = x < y < z;
printf("%d\n", i);
return 0;
Ans : 1
#include<stdio.h>
int main()
b = 300;
c = 200;
return 0;
Ans : 100,200
#include<stdio.h>
#include<conio.h>
void main()
printf("%d",++(*p));
#include<stdio.h>
#include <conio.h>
void main()
clrscr();
printf("c=%d",c);
getch();
Ans : c=2
#include<stdio.h>
#include <conio.h>
void main()
clrscr();
printf("\nab");
printf("\bsi");
printf("\rha");
getch();
Ans : hai
#include<stdio.h>
int main(){
int a = 130;
char *ptr;
printf("%d ",*ptr);
return 0;
A. -126 (Ans)
C. Garbage value
D. Compile Time Error
#include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
k++;
printf("%d ",**k);
return 0;
A. Garbage value
D. Linker Error
#include<stdio.h>
int main(){
int i = 3;
int *j;
j = &i;
j++;
printf("%d ",*j);
return 0;
A. Linker Error
C. Compilation Error
#include<stdio.h>
#include<string.h>
int main(){
char a[22];
strcpy(a, "world");
return 0;
C. Compilation Error
D. Garbage value
#include<stdio.h>
#include<string.h>
int main(){
*ptr = "world";
return 0;
A. Linker Error
D. Garbage value
#include<stdio.h>
int main()
printf(ptr + 4);
return 0;
A. oworld (Ans)
B. world
C. hell
D. hello
#include<stdio.h>
int main()
return 0;
A. Address of 2
B. Compilation Error
C. 2 (Ans)
#include<stdio.h>
#include<string.h>
int main(){
register a = 1;
ptr = &a;
printf("%u",ptr);
return 0;
A. Address of a
C. Garbage value
#include<stdio.h>
#include<string.h>
int main(){
char a = 30, b = 5;
printf("%d", p - q);
return 0;
A. 1 (Ans)
C. Compilation Error
D. 25
#include<stdio.h>
int main(){
int *ptr, b;
b = sizeof(ptr);
printf("%d" , b);
return 0;
A. 2
B. 4 (Ans)
C. Compilation Error
#include<stdio.h>
struct classroom
int students[7];
};
int main()
int *ptr;
printf("%d",*(ptr + 4));
return 0;
A. 5
B. 11 (Ans)
C. 13
D. 7
#include<stdio.h>
printf("%d", *arr);
return &arr;
int main(){
unsigned long int (*ptr)[5];
ptr = function();
return 0;
A. 2, 5
B. 2, 7
C. 2, 11 (Ans)
D. Compilation error
#include<stdio.h>
int main(){
int a = 25, b;
ptr = &a;
ptr1 = &b;
b = 36;
return 0;
A. 25 45632845
C. Compilation Error
int main(){
int * ptr ;
printf("%d", sizeof(ptr));
return 0;
A. 4 (Ans)
B. 8
C. 2
D. compilation error
#include<stdio.h>
int main(){
int *ptr = 2;
printf("%d", sizeof(ptr));
return 0;
A. Garbage value
B. 2
D. 4
#include<stdio.h>
int main(){
int *ptr;
*ptr = 5;
printf("%d" , *ptr);
return 0;
A. compilation error
C. 5
D. linker error
#include<stdio.h>
int main(){
int a = 36;
int *ptr;
ptr = &a;
return 0;
A. Address Value
B. Value Address
D. Compilation error
int main(){
num++;
return 0;
A. Compilation error
#include<stdio.h>
int main(){
int i = 25;
int *j;
int **k;
j = &i;
k = &j;
printf("%u %u %u ",k,*k,**k);
return 0;
D. compilation error
#include<stdio.h>
int main(){
int a, b, c;
char *p = 0;
int *q = 0;
double *r = 0;
a = (int)(p + 1);
b = (int)(q + 1);
c = (int)(r + 1);
return 0;
A. Runtime error
B. 0 0 0
C. Compilation error
D. 1 4 8 (Ans)
#include<stdio.h>
int main()
char *ptr;
ptr += 6;
printf("%s",ptr);
return 0;
A. compilation error
B. Runtime error
C. pointers
#include<stdio.h>
int main()
const int a = 5;
ptr = &a;
*ptr = 10;
printf("%d\n", a);
return 0;
B. Garbage Value
C. Address
D. 5
int main()
return 0;
A. 1
B. compilation error
C. Runtime error
D. 4 (Ans)
#include<stdio.h>
void function(char**);
int main()
function(arr);
return 0;
char *ptr1;
printf("%s\n", ptr1);
A. cat (Ans)
B. bat
C. dog
D. egg
#include<stdio.h>
int main()
struct node
int a, b, c;
};
return 0;
A. 3
B. 5
C. Compilation error
D. 6 (Ans)
26. What will be the output of the C program?
#include<stdio.h>
int main(){
arr[15] = *ptr;
printf("%c",arr[0]);
return 0;
C. P
#include<stdio.h>
int main(){
int *ptr;
ptr = arr;
printf("%c",ptr[1]);
return 0;
A. Garbage value
B. o
C. t (Ans)
#include<stdio.h>
int main()
int a = 10, b = 6;
int *ptr;
ptr = &b;
return 0;
C. Compilation error
D. 60 (Ans)
#include<stdio.h>
int main()
int *iptr;
return 0;
A. 12 (Ans)
B. 13
C. Compilation Error
D. Garbage value
#include<stdio.h>
int main()
printf("%c\n", **i);
return 0;
A. Delhi
B. Garbage address
C. D (Ans)
#include<stdio.h>
int main(){
printf("%c%c%c\n", **i,**j,**k);
return 0;
A. Upa
B. USA (Ans)
C. UAE
#include<stdio.h>
int main(){
ptr = &array[1];
ptr1 = ptr + 3;
*ptr1 = 101;
printf("%c", *ptr++);
return 0;
A. not
B. Knot
C. note (Ans)
D. garbage value
33. What will be the output of the C program?
#include<stdio.h>
int main()
printf("%s", ++ptr);
return 0;
A. Pointer-to-String
B. o
C. ointer-to-String (Ans)
#include<stdio.h>
int main()
int i;
printf("%s", str++);
return 0;
A. Hisis (Ans)
B. Hisiss
C. HisHisHis
#include<stdio.h>
int main()
ptr = (&arr[1]++);
printf("%s",ptr++);
return 0;
A. ango
B. ngo
D. Mango
#include<stdio.h>
int main(){
int i = 5;
void *vptr;
vptr = &i;
return 0;
A. 5
B. garbage address
C. garbage value
#include<stdio.h>
int main(){
void *vptr;
vptr = &ptr;
printf("%s" , ?);
return 0;
B. (char **)vptr
C. *(char *)vptr
D. (char *)vptr
#include<stdio.h>
int main()
printf("%s",ptr);
return 0;
B. NULL
C. error (Ans)
39. Which type of pointer is a most convention way of storing raw address in c programming?
B. Null pointer
C. Integer pointer
D. Double pointer
#include<stdio.h>
int main()
int i = 5,*ptr;
ptr= &i;
void *vptr;
vptr = &ptr;
return 0;
A. **(int **)vptr
B. **(int ***)vptr
C. **(int ****)vptr
val=strcmp(str,"includehelp.com");
printf("%d",val);
return 0;
}
int main()
{
char str[];
strcpy(str,"Hello");
printf("%s",str);
return 0;
}
#include <stdio.h>
int main()
{
char str[8]="IncludeHelp";
printf("%s",str);
return 0;
}
4) Which of the following function sets first n characters of a string to a given character?
A. strinit()
B. strnset()
C. strset()
D. strcset()
ans:Option B
Explanation:
Declaration:
char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
return 0;
}
Output:
A. printf("\n");
B. echo "\\n";
C. printf('\n');
D. printf("\\n");
and: D
6)The library function used to find the last occurrence of a character in a string is
A. strnstr()
B. laststr()
C. strrchr()
D. strstr()
ans:C
#include <string.h>
#include <stdio.h>
int main(void)
{
char text[] = "I learn through IndiaBIX.com";
char *ptr, c = 'i';
7)Which of the following function is more appropriate for reading in a multi-word string?
A. printf();
B. scanf();
C. gets();
D. puts();
Answer: Option C
8)If the two strings are identical, then strcmp() function returns
ans: -1
9)What is (void*)0?
ans: A
A. stdio.h
B. stddef.h
C. stdio.h and stddef.h
D. math.h
ans: C
11)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. ->
ans: Option D
12)What would be the equivalent pointer expression for referring the array element a[i][j][k][l]?
A. ((((a+i)+j)+k)+l)
B. *(*(*(*(a+i)+j)+k)+l)
C. (((a+i)+j)+k+l)
D. ((a+i)+j+k+l)
ans: Option B
14)In C, if you pass an array as an argument to a function, what actually gets passed?
ans:C
15)main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
Answer:
54321
When static storage class is given, it is initialized once. The change in the value of a static variable is
retained even between the function calls. Main is also treated like any other ordinary function, which
can be called recursively.
ans:I
& is a reference operator, * is de-reference operator, We can use these operators any number of
times. str points the first character of IncludeHelp, *str points "I", * & again reference and de-
reference the value of str.
#include <stdio.h>
int main()
{
int MAX=10;
int array[MAX];
printf("size of array is = %d",sizeof(array);
return 0;
}
ans:size of array is = 40
ans:4
You can ignore value within the subscript [] when you are initialising array with elements, but here no
initialisation found.
19)#include <stdio.h>
int main()
{
int arr[5];
// Assume that base address of arr is 2000 and size of integer
// is 32 bit
arr++;
printf("%u", arr);
return 0;
}
1.2002
2.2004
3.2020
4.lvalue required
ans:4
Array name in C is implemented by a constant pointer. It is not possible to apply increment and
decrement on constant types.
ans:10000
If we initialize an array with fewer members, all remaining members are automatically initialized as 0.
int main()
{
char str1[] = "GeeksQuiz";
char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i', 'z'};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
printf("n1 = %d, n2 = %d", n1, n2);
return 0;
}
ans:n1=10,n2=9
23)int main()
{
char a[2][3][3] = {'g','e','e','k','s','q','u','i','z'};
printf("%s ", **a);
return 0;
}
ans: geeksquiz
We have created a 3D array that should have 2*3*3 (= 18) elements, but we are initializing only 9 of
them. In C, when we initialize less no of elements in an array all uninitialized elements become 曾 0' in
case of char and 0 in case of integers.
24)#include<stdio.h>
void swap(char *str1, char *str2)
{
char *temp = str1;
str1 = str2;
str2 = temp;
}
int main()
{
char *str1 = "Geeks";
char *str2 = "Quiz";
swap(str1, str2);
printf("str1 is %s, str2 is %s", str1, str2);
return 0;
}
25)#include<stdio.h>
int main()
{
char str[20] = "GeeksQuiz";
printf ("%d", sizeof(str));
return 0;
}
ans:20
ques.txt
Displaying ques.txt.
1. main() { int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c); ++q;
} for(j=0;j<5;j++)
{ printf(" %d ",*p); ++p; } }
Answer: 2 2 2 2 2 2 3 4 6 5
Explanation:
Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c ,
the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will
be printed.
2.
void main() {
int const * p=5;
printf("%d",++(*p));
} Answer: Compiler error: Cannot modify a constant value. Explanation: p is a pointer to a "constant
integer". But we tried to change the value of the "constant integer".
3.
main() {
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}
Answer: 1 2 Explanation: The sizeof() operator gives the number of bytes taken by its operand.
P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p)
gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives
2.
4.
#include<stdio.h>
main() {
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer: 77
Explanation: p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n'
and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The
value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII
value of 'b' is 98. Now performing (11 + 98 – 32), we get 77("M"); So we get the output 77 :: "M"
(Ascii is 77).
5.
void main()
{
char far *farther,*farthest;
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
Answer: 4..2 Explanation: the second pointer is of char type and not a far pointer
6,
main()
{
char *p; p="Hello";
printf("%c\n",*&*p);
} Answer: H
Explanation: * is a dereference operator & is a reference operator. They can be applied any number
of times provided it is meaningful. Here p points to the first character in the string "Hello". *p
dereferences it and so its value is H. Again & references it to an address and * dereferences it to the
value H.
7.
main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++) printf("%s",names[i]);
} Answer: Compiler error: Lvalue required in function main Explanation: Array names are pointer
constants. So it cannot be modified.
8.
# include <stdio.h>
int one_d[]={1,2,3};
main()
{
int *ptr; ptr=one_d;
ptr+=3;
printf("%d",*ptr);
} Answer: garbage value
Explanation: ptr pointer is pointing to out of the array range of one_d.
9. # include<stdio.h>
aaa() {
printf("hi");
} bbb(){ printf("hello");
} ccc(){ printf("bye");
} main() { int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2](); } Answer: bye
Explanation: ptr is array of pointers to functions of return type int.ptr[0] is assigned to address of the
function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc respectively. ptr[2]() is in effect of writing
ccc(), since ptr[2] points to ccc.
10.
In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0; /* add a stmt here*/ }
Answer:
*k = &a
Explanation: The argument of the function is a pointer to a pointer.
11.
main() {
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
} Answer: 300
Explanation: The pointer points to % since it is incremented twice and again decremented by 2, it
points to '%d\n' and 300 is printed.
12.
void main()
{
void *v;
int integer=2;
int *i=&integer;
v=i;
printf("%d",(int*)*v);
}
Answer: Compiler Error. We cannot apply indirection on type void*.
Explanation: Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void
pointers are normally used for,
1. Passing generic pointers to functions and returning such pointers. 2. As a intermediate pointer
type.
3. Used when the exact pointer type will be known at a later point of time.
#include<stdio.h>
int main()
char *ptr;
ptr = string;
ptr += 6;
printf("%s",ptr);
return 0;
#include<stdio.h>
int main()
const int a = 5;
ptr = &a;
*ptr = 10;
printf("%d\n", a);
return 0;
Ans: address
#include<stdio.h>
int main()
return 0;
Ans: 4
#include<stdio.h>
void function(char**);
int main()
function(arr);
return 0;
char *ptr1;
printf("%s\n", ptr1);
}
Ans: cat
#include<stdio.h>
int main(){
arr[15] = *ptr;
printf("%c",arr[0]);
return 0;
#include<stdio.h>
int main(){
int *ptr;
ptr = arr;
printf("%c",ptr[1]);
return 0;
Ans: t
#include<stdio.h>
int main()
int a = 10, b = 6;
int *ptr;
ptr = &b;
return 0;
Ans: 60
8. Which type of pointer is a most convention way of storing raw address in c programming? Ans:
void pointer
ARRAYS:
9.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?
Answer: Option C
int (*ptr)[10];
Answer: Option B
11.What will be the output of the program ?
#include<stdio.h>
int main()
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
return 0;
A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20
Answer: Option C
#include<stdio.h>
int main()
{
{
*(*(i+p)+j), *(*(p+j)+i));
}
}
return 0;
A. 1, 1, 1, 1
2, 3, 2, 3
3, 2, 3, 2
4, 4, 4, 4
B. 1, 2, 1, 2
2, 3, 2, 3
3, 4, 3, 4
4, 2, 4, 2
C. 1, 1, 1, 1
2, 2, 2, 2
2, 2, 2, 2
3, 3, 3, 3
D. 1, 2, 3, 4
2, 3, 4, 1
3, 4, 1, 2
4, 1, 2, 3
Answer: Option C
#include<stdio.h>
int main()
int i;
fun(4, arr);
printf("%d,", arr[i]);
return 0;
int *p=0;
int i=0;
while(i++ < n)
p = &arr[i];
*p=0;
A. 2, 3, 4, 5
B. 1, 2, 3, 4
C. 0, 1, 2, 3
D. 3, 2, 1 0
Answer: Option B
#include<stdio.h>
int main()
int *ptr;
ptr = &a[0][0];
fun(&ptr);
return 0;
printf("%d\n", **p);
A. 1
B. 2
C. 3
D. 4
Answer: Option A
15.What will be the output of the program if the array begins at 65472 and each integer occupies 2
bytes?
#include<stdio.h>
int main()
return 0;
A. 65474, 65476
B. 65480, 65496
C. 65480, 65488
D. 65474, 65488
Answer: Option B
#include<stdio.h>
int main()
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
return 0;
A. 1, 2, 3, 4, 5,
B. Garbage value, 1, 2, 3, 4,
C. 0, 1, 2, 3, 4,
D. 2, 3, 4, 5, 6,
Answer: Option B
#include <stdio.h>
int main()
int arr[5];
arr++;
printf("%u", arr);
return 0;
A.2002
B.2004
C.2020
D.lvalue required
Answer: Option D
18.What will be the output of following program?
#include <stdio.h>
int main()
printf("%d...%d",*array,*(array+3)* *array);
return 0;
A. Error
B. 10...40
C. 10...300
D. 10....400
Answer: Option D
#include <stdio.h>
int main()
{ int a[5]={1,2,3,4,5},b[5]={10,20,30,40,50},tally;
for(tally=0;tally< 5;++tally)
*(a+tally)=*(tally+a)+ *(b+tally);
for(tally=0;tally< 5;tally++)
printf("%d ",*(a+tally));
return 0;
A. 1 2 3 4 5
B. 10 20 30 40 50
C. 11 22 33 44 55
D. Error
Answer: Option C
#include <stdio.h>
int main()
{ int a[5]={0x00,0x01,0x02,0x03,0x04},i;
i=4;
while(a[i])
{
printf("%02d ",*a+i);
--i;
}
return 0;
A. 00 01 02 03 04
B. 04 03 02 01 00
C. 04 03 02 01
D. 01 02 03 04
Answer: Option C
.What will be the output of the C program?
#include<stdio.h>
int main()
ptr = &arr;
ptr1 = *ptr + 3;
A. 1--11
B. 1-7
C. 1--4
D. 1--some address
Option: C
Explanation
i.e) ptr1 = 4;
printf("%d--%d", 1, 4);
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int i = 5,*ptr;
ptr= &i;
void *vptr;
vptr = &ptr;
return 0;
A. **(int **)vptr
B. **(int ***)vptr
C. **(int ****)vptr
Explanation
All declarations are true, because typecasting can be with more asterisks but not with lesser asterisks.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int a = 25, b;
ptr = &a;
ptr1 = &b;
b = 36;
return 0;
A. 25 45632845
C. Compilation Error
D. 25 36
Option: D
Explanation
ptr holds the address of a variableA and ptr1 holds the address of a variable B . The value of A is 25
and B is 36.
--------------------------------------------------------------------------------------------
4.Which type of pointer is a most convention way of storing raw address in c programming?
A. Void pointer
B. Null pointer
C. Integer pointer
D. Double pointer
Option: A
Explanation:
Void pointer is alone generic because void pointer does not have any associated data type with it.
Being generic void pointer can store raw address of a variable irrespective of it's datatype.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
printf("%s",ptr);
return 0;
B. NULL
C. error
Option: C
Explanation
NULL is used for stylistic convention. Thus NULL itself a macro which is defined in #include<stdio.h>
header files, thus modifing macro cause no error. Thus outputted "error"
--------------------------------------------------------------------------------------------
6. Fill the question mark to get "void pointer" as an output?
#include<stdio.h>
int main()
void *vptr;
vptr = &ptr;
printf("%s" , ?);
return 0;
A. *(char **)vptr
B. (char **)vptr
C. *(char *)vptr
D. (char *)vptr
Option: A
In this program we used void pointer to display the string stored in another char pointer variable.
Thus by using pointer to pointer typecasting *(char **)vptr we outputted the string "void pointer"
--------------------------------------------------------------------------------------------
#include<stdio.h>
#include<string.h>
int main()
char a = 30, b = 5;
printf("%d", p - q);
return 0;
A. 1
C. Compilation Error
D. 25
Option: A
Explanation
Difference between any two variables of same data type are always one.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int a, b, c;
a = ++arr[1];
b = arr[1]++;
c = arr[a++];
printf("%d--%d--%d", a, b, c);
return 0;
A. 4--3--25
B. 3--3--2
5
C. 4--4--25
D. 3--4--25
Option: A
here, a = ++arr[1];
i.e) a = 3 //arr[2];
b = arr[1]++;
i.e) b = 3 //arr[2];
c = arr[a++];
i.e) c = 25 //arr[4];
printf("%d--%d--%d",a, b, c);
printf("%d--%d--%d",4, 3, 25);
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int *b = arr;
int *c = arr + 1;
printf("%d", c - b);
return 0;
A. 0
B. Runtime Error
C. 25
D. Some address
Option: C
Explanation
Now *b = 2292932; *c = arr + 1; i.e) *c contains the address which is located next to the last value
address in an arr[5][5][5], which is the address location next to that 25th value in an array arr[5][5][5].
Now *c = 2293032;
printf("%d", 100/ sizeof(int)); as it is an integer type values we have to divide it by sizeof(int) to display
value not the address.
printf("%d", 25);
thus 25
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
for(j = 0;j<5;j++)
++ptr;
}
A. 2 2 2 2 2
B. 1 1 1 1 1
C. 1 2 3 4 5
Option: B
Explanation
Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr.
So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
return 0;
A. 0
B. Compilation error
C. 1
D. 4
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
char ***p;
p = ptr;
**++p;
printf("%s",*--*++p + 2);
A. prints nothing
B. ke
C. ike
D. Compilation error
------------------------------------------------------------------------------------------
13.In C, if you pass an array as an argument to a function, what actually gets passed?
Answer: Option C
Explanation:
The statement 'C' is correct. When we pass an array as a funtion argument, the base address of the
array will be passed
--------------------------------------------------------------------------------------------
#include<stdio.h>
void function(char**);
Int main()
{
char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };
function(arr);
return 0;
char *ptr1;
printf("%s\n", ptr1);
A. cat
B. bat
C. dog
D. egg
Option: A
Explanation
Here function() gives the address of first value("ant") in an arr.This address is summationed by a
sizeof(int) which is 4. now the address in ptr points the value eggs, which is then reduced by 2 . now it
points to the value catwhich is finally displayed
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
char *ptr;
ptr += 6;
printf("%s",ptr);
return 0;
}
A. compilation error
B. Runtime error
C. from 2braces.com
D. C from 2braces.com
Option: D
Explanation
Each letter in string[] array is stored in seperate address. The starting address in string[] array is stored
a pointer variable ptr which is then incremented by 6. Thus "learn " is neglected and "C from
2braces.com" is displayed.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
return 0;
A. 1
B. compilation error
C. Runtime error
D. 4
Option: D
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int *ptr = 2;
printf("%d", sizeof(ptr));
return 0;
A. Garbage value
B. 2
C. Compilation error
D. 4
Option: C
Explanation
ptr is the pointer variable of integer data type. Thus ptr can not be initialised by any integer value
other than 0.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
arr[15] = *ptr;
printf("%c",arr[0]);
return 0;
A. Garbage value
B. Run time error
C. P
Option: A
Explanation
A pointer variable which is initialized by a string cannot to assigned to a array variable of size n. Thus
some garbage value or empty output will be displayed
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int a = 10, b = 6;
int *ptr;
ptr = &b;
return 0;
C. Compilation error
D. 60
Option: D
Explanation
i.e) 10 * 6 = 60
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
int *iptr;
iptr = *arr ;
return 0;
A. 12
B. 13
C. Compilation Error
D. Garbage value
Option: A
Explanation:
Here, iptr holds the address of first element in an array arr i.e) address of 10. In printf statement we
increment the address by (2 * sizeof(int)). Thus iptr now points to the address of 12. Asterisks (*) in
printf statement prints the value inside the address i.e) 12 is outputted.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
int arr[1] = {2};
printf("%d", 0[arr]);
return 0;
A. Compilation error
C. 2
D. 0
Option: C
Explanation
#include<stdio.h>
int main()
int *ptr;
ptr = &arr;
array(&ptr);
return 0;
printf("%d", **p);
B. 3
C. address of ptr
D. Runtime error
Option: B
Explanation
array(&ptr);
printf("%d", **p);
Thus 3 is outputted.
#include<stdio.h>
int main()
return 0;
A. 3
B. 5
C. Compilation error
D. 6
Option: D
Explanation
Here the pointer variable stores the address of first value in struct node num = {3, 5, 6}; which is
incremented by 2 and then the value 6 is finally displayed.
--------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
printf("%s", ++ptr);
return 0;
A. Pointer-to-String
B. o
C. Pointer-to-String
Option: C
Explanation
Here, the starting address i.e) The address of P is skipped by pre incrementing the address. "Noting
more than that".
char *p;
p = (char*) malloc(100);
#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}
A. #include<conio.h>
B. #include<math.h>
C. #include<stdlib.h>
D. #include<dos.h>
Answer: Option B
10) The keyword used to transfer control from a function back to the calling function is
A. switch
B. goto
C. go back
D. return
Answer: Option D
11) How many times the program will print "hello" ?
#include<stdio.h>
int main()
{
printf("hello");
main();
return 0;
}
A. Infinite times
B. 32767 times
C. 65535 times
D. Till stack overflows
Answer: Option D
Answer: Option A
13) 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: Option D
14) What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
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: Option B
15) The operator used to get value at address stored in a pointer variable is
A. *
B. &
C. &&
D. ||
Answer: Option A
Solution: Option (A) is valid as p is a pointer pointing to character ‘s’ of “string1”. Using ++p, p will
point to character ‘t’ in “string1”. Therefore, *++p will print ‘t’.
Option (B) is invalid as q being base address of character array, ++q(increasing base address) is invalid.
Option (C) is valid as r is a pointer pointing to character ‘s’ of “string1”. Therefore,
#include <stdio.h>
int main()
{
char str[11] = "hello";
char *str1 = "world";
strcat(str, str1);
printf("%s %d", str, str[10]);
)
a) helloworld 0
b) helloworld anyvalue
c) worldhello 0
d) Segmentation fault/code crash
Answer: a
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
a. Hello
b. Hello
c. Hello World
d. WorldHello
Answer: (c).
#include<stdio.h>
int main()
{
char p[] = "%d\n";
p[1] = 'c';
printf(p, 65);
return 0;
}
a. A
b. a
c. c
d. 65
Answer: (a).
#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "Compsci\0\Bits\0";
printf("%s\n", str);
return 0;
}
a. Bits
b. Compsci
c. Compsci Bits
d. Compsci\0Bits
Answer: (b).
Answer: (d).
24) the operators > and < are meaningfull when used with pointers if,
D.None of these.
Answer: Option C
D.We can change the pointer as well as the value pointed by it.
Answer: Option A
Solution: int * : pointer to int
int const * : pointer to const int
int * const : const pointer to int
int const * const : const pointer to const int
Now the first const can be on either side of the type so:
So the above declaration is pointer to const int. Which means,we cannot change the value pointed by
ptr.
main()
char *p;
p=”Hello”;
printf(“%c”,*&*p);
A. Hello
B. H
D. None of th
a.R-values
c.Local variables
d.Member of structure
ans:c
3.#include<stdio.h>
main()
int i=10;
void *p=&i;
printf(“%d”,(int)*p);
b.segmentation fault
c.10
d.undefined behaviour
ans:a
4.#include<stdio.h>
main()
int i=10;
void *p=&i;
printf(“%d”,*(float*)p);
Ans:0.000000
char **argv;
ans:c
6.#include<stdio.h>
int main()
int a[5]={2,3};
printf(“%d%d%d”,a[2],a[3],a[4]);
return 0;
a.garbage values
b.2,3,3
c.3,2,2
d.0,0,0
ans:d
a.stdio.h
b.stddef.h
ans:c
8.what is sizeof() in c?
a.operator
b.function
c.macro
d.none of these
ans:a
9.int main()
extern int i;
i=20;
printf(“%d”,sizeof(i));
return 0;
}
a.20
b.0
ans:c
10.void main()
int a=printf(“cpp.com”);
printf(“%d”,a);
a.compilation error
b.0
c.cpp.com
d.cpp.com7
11.int main()
int x;
x=10,20,30;
printf(“%d”,x);
return 0;
a.10
b.20
c.10,20,30
d.compilation error
ans:10
void main()
int a=0;
while(a++<5)
printf(“cppbuzz.com”);
a.4
b.5
c.compilation error
d.0
void main()
int a=0;
while(a)
printf(“cppbuzz.com”);
a.4
b.infinite time
c.compilation error
d.0
ans:d
13.void main()
int a[10];
printf(“%d%d”,a[-1],a[12]);
a.0 0
b.garbage value,0
ans:c
14.#include<stdio.h>
void main()
int a[3][4]={1,2,3,4,4,3,2,1,7,8,9,0};
printf(“%u%u”,a+1,&a+1);
a.65474,65488
b.65490,65488
c.65480,65496
ans:c
a.data file
b.string
c.stdin
ans:b
char *p;
p=(char*)malloc(100);
A)char p = *malloc(100);
C)char *p = (char*)malloc(100);
2. #include<stdio.h>
int main(){
int a = 130;
char *ptr;
printf("%d ",*ptr);
return 0;
A. -126
C. Garbage value
Option: A
Explanation
Here a variable a holds the value 130 of integer datatypes, which is then type casted to char
datatypes using pointer variable. As we know that a value 130 is exceeding the char range( -128 to
127), thus it loops through its range.
For Example
128 = -128
129 = -127
130 = -126
140 = -125
3. #include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
k++;
printf("%d ",**k);
return 0;
A.Garbage value
B. Compilation Error
D. Linker Error
Option: C
Explanation
Here k is the pointer variable which holds the address of another pointer variable j. where j is also a
pointer variable which also holds the address of another variable i. Now when the address of a
pointer variable k is incremented by 1 , then k hold some other garbage value which is not the address
of any other variable. Thus runtime error occurs.
4.#include<stdio.h>
int main(){
int i = 3;
int *j;
j = &i;
j++;
printf("%d ",*j);
return 0;
A.Linker error
C.Compilation error
D. Garbage value
Option: D
Explanation
Here j is the pointer variable which holds the address of another variable called i. When j is
incremented, the address stored in j is incremented. As a result some garbage value will be displayed
as we had not initialized anything to the address next to the address of a variable i
5. #include<stdio.h>
#include<string.h>
int main(){
char a[22];
*ptr = "world";
return 0;
A. Linker Error
C. Compilation Error
D. Garbage value
Option: C
Explanation
ptr is a pointer variable of character data type, string "world" can be set to the pointer variable ptr
only at the initializing time.
#include<stdio.h>
int main()
printf("%c\n",*&*ptr);
return 0;
A. Address of 2
B. Compilation Error
C. 2
Option: C
Explanation
In pointer, address operator and Multiplication operator are always cancel each other. Thus *&*ptr =
*ptr.
7. #include<stdio.h>
#include<string.h>
int main(){
register a = 1;
ptr = &a;
printf("%u",ptr);
return 0;
A. Address of a
C. Garbage value
Option: D
Explanation
"a" is a register variable which holds a value 1. It must be noted that variable a hold its value 1 in a
register but not in computer memory location thus the pointer variable ptr cannot hold the address of
a.
8. #include<stdio.h>
struct classroom
int students[7];
};
int main()
int *ptr;
printf("%d",*(ptr + 4));
return 0;
A. 5
B. 11
C. 13
D. 7
Option: B
Explanation
Here a pointer variable ptr holds the address of a first value (2) of an object cr, then the address of
the pointer variable is incremented by 4 and then its value is displayed .
9. #include<stdio.h>
int main(){
int a = 25, b;
ptr = &a;
ptr1 = &b;
b = 36;
return 0;
A. 25 45632845
D. 25 36
Option: D
Explanation
ptr holds the address of a variable A and ptr1 holds the address of a variable B . The value ofA is 25
and B is 36.
10. #include<stdio.h>
int main(){
int * ptr ;
printf("%d", sizeof(ptr));
return 0;
A. 4
B. 8
C. 2
D. compilation error
Option: A
Explanation
11. #include<stdio.h>
int main()
char temp;
printf("%d\n", temp);
return 0;
}
A. 2
B. 3
C. 4
D. 5
Option: C
Explanation
Here,temp=(arr+ 1)[2];
Let us consider the address of first element in an array arr[10] is 2293416 then temp looks like this
temp = (2293416 + 1)[2];
Now temp =(2293420)[2];, which denotes temp = "index value of 2 from the address 2293420(value =
2)";
Now temp = 4;(address = 2293428)
Thus the program outputted 4.
12. #include<stdio.h>
int main()
a[0][1][2] = 5;
printf("%d",*(*(*(a+0)+1)+2));
return 0;
A. printf("%d",*(((a+0)+1)+2));
B. printf("%d",*(*(*(a+0)+1)+2));
C. printf("%d",***((a+0)+1)+2);
Option: B
Explanation
Simply, this is a format for naviting to a value using the address of a first element in an array.
13. #include<stdio.h>
void fun(char**);
int main()
{
char *arr[] = { "bat", "cat", "fat", "hat", "mat", "pat" };
fun(arr);
return 0;
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
A. mat
B. fat
C. hat
D. cat
Option: C
Explanation
fun(arr) returns the address of first element in an array arr Let we start from the function void fun().
*t is a pointer variable which holds t = (p += sizeof(int))[-1];
ie ) t = (p = p + sizeof(int)) [-1];
t = (p = p + 4) [-1];
t = (p = address of bat + 4)[-1];
let us consider a address of bat is 2293416,
t = (p = 2293416 + 4)[-1];
t = (p = 2293432)[-1]
t = ("mat")[-1]; // index from "mat"
t = "hat";
thus hat is outputted.
14. #include<stdio.h>
int main()
return 0;
}
A. 0
B. Compilation error
C. 1
D. 4
Option: C
Explanation
printf("%d", (&arr+1 - &arr)); let us consider the address of an array arr starts from 2293420
then, printf("%d", (2293420 +1 - 2293420);
printf("%d", 0 + 1);
printf("%d", 1);
Thus 1 is outputted.
15. #include<stdio.h>
int main(){
i = j = k = 00;
for(i = 0;i<rows;i++)
for(j = 0;j<colums;j++)
if(a[k][j]<k)
k = a[i][j];
printf("%d\n", k);
return 0;
A. 00
B. No output
C. 0
D. 7
Option: C
Explanation
Initially we set i = 0, j = 0, k = 0. zero be never greater than any integer values in an array a[3][4], thus
if condition fails. and 0 is outputted.
16. #include<stdio.h>
int main()
for(j = 0;j<5;j++)
++ptr;
A. 2 2 2 2 2
B. 1 1 1 1 1
C. 1 2 3 4 5
Option: B
Explanation
Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr.
So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.
17. #include<stdio.h>
int main()
int i = 0;
printf("Hello");
for(i = 0;i<4;i++){
printf("%c", s[i]);
}
return 0;
A. Hello
B. Compilation error
C. Hell
Option: C
Explanation
18. #include<stdio.h>
int main()
int i = 0;
for(i = 0;i<4;i++)
printf("%c", s[i]);
return 0;
A. \0 \0 \0
B. \0 \0 \0 \0
C. No output
Option: C
Explanation
\0 = NULL. Thus compiler prints nothing.
19. #include<stdio.h>
int main()
p = &s[3];
str = p;
str1 = s;
return 0;
A. 76
B. 77
C. 78
D. 79
Option: B
Explanation
p = &s[3].
i.e) p = address of '\n';
str = p;
i.e) str = address of p;
str1 = s;
str1 = address of 'a';
printf ("%d", ++*p + ++*str1 - 32);
i.e) printf("%d", ++\n + a -32);
i.e) printf("%d", 12 + 97 -32);
i.e) printf("%d", 12 + 65);
i.e) printf("%d", 77);
Thus 77 is outputted.
20. #include<stdio.h>
int main()
int i = 0;
printf("Hello");
for(i = 0;i<4;i++)
printf("%c", s[i]);
return 0;
A. Hello
B. Hell
C. No output
D. Compilation error
Option: C
Explanation
21. #include<stdio.h>
int main()
printf("%d", arr[3]);
return 0;
A. 3
B. 4
D. Compilation error
Option: C
Explanation
Here the size of an array is 2, but the value inside array is exceed 2. Thus it prints garbage value for
index more than 1
22. #include<stdio.h>
int main()
ptr = &arr;
ptr1 = *ptr + 3;
A. 1--11
B. 1-7
C. 1--4
D. 1--some address
Option: C
Explanation
23. #include<stdio.h>
int main()
int arr[5] = { 1, 3, 5, 7, 11 };
int *ptr;
ptr = &arr;
A. 1
B. 2
C. 3
D. Runtime error
Option: B
Explanation
24.#include <stdio.h>
int main()
int count=0;
var[++count]=++count;
for(count=0;count<5;count++)
printf("%d ",var[count]);
return 0;
A.0 1 0 0 0
B.0 2 0 0 0
C.0 0 2 0 0
D.0 0 0 0 0
Option C
25)
#include "stdio.h"
int main()
*ppp++; // Line 1
OPTIONS:
a)C B
b)B A
c)B C
d)C A
OUTPUT: (d) C A
Explanation:
Line 1 : Now, ppp points to next memory location i.e., index 1 of the character array.
Line 2 : Firstly, –*ppp= –(*ppp) is executed and hence the value ‘B’ (which is in the index 1 position of
the char[] array) gets decremented by 1(i.e., it becomes ‘A’)and it is sent for printing. Then *++ppp=
*(++ppp) is executed which initially increments the pointer to the next element of the array and prints
the value in that index number 2 which is ‘C’. Although –*ppp is executed first compared to *++ppp,
the display will be shown in the order as we mentioned in the printf() function in line 2. Hence we get
output as C A.
char *p;
p=(char*)malloc(100);
A)char p = *malloc(100);
C)char *p = (char*)malloc(100);
D)char *p = (char *)(malloc*)(100);
Option:c
2. #include<stdio.h>
int main(){
int a = 130;
char *ptr;
printf("%d ",*ptr);
return 0;
A. -126
C. Garbage value
Option: A
Explanation
Here a variable a holds the value 130 of integer datatypes, which is then type casted to char
datatypes using pointer variable. As we know that a value 130 is exceeding the char range( -128 to
127), thus it loops through its range.
For Example
128 = -128
129 = -127
130 = -126
140 = -125
3. #include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
k++;
printf("%d ",**k);
return 0;
A.Garbage value
B. Compilation Error
D. Linker Error
Option: C
Explanation
Here k is the pointer variable which holds the address of another pointer variable j. where j is also a
pointer variable which also holds the address of another variable i. Now when the address of a
pointer variable k is incremented by 1 , then k hold some other garbage value which is not the address
of any other variable. Thus runtime error occurs.
4.#include<stdio.h>
int main(){
int i = 3;
int *j;
j = &i;
j++;
printf("%d ",*j);
return 0;
A.Linker error
C.Compilation error
D. Garbage value
Option: D
Explanation
Here j is the pointer variable which holds the address of another variable called i. When j is
incremented, the address stored in j is incremented. As a result some garbage value will be displayed
as we had not initialized anything to the address next to the address of a variable i
5. #include<stdio.h>
#include<string.h>
int main(){
char a[22];
*ptr = "world";
return 0;
A. Linker Error
C. Compilation Error
D. Garbage value
Option: C
Explanation
ptr is a pointer variable of character data type, string "world" can be set to the pointer variable ptr
only at the initializing time.
#include<stdio.h>
int main()
printf("%c\n",*&*ptr);
return 0;
}
A. Address of 2
B. Compilation Error
C. 2
Option: C
Explanation
In pointer, address operator and Multiplication operator are always cancel each other. Thus *&*ptr =
*ptr.
7. #include<stdio.h>
#include<string.h>
int main(){
register a = 1;
ptr = &a;
printf("%u",ptr);
return 0;
A. Address of a
C. Garbage value
Option: D
Explanation
"a" is a register variable which holds a value 1. It must be noted that variable a hold its value 1 in a
register but not in computer memory location thus the pointer variable ptr cannot hold the address of
a.
8. #include<stdio.h>
struct classroom
{
int students[7];
};
int main()
int *ptr;
printf("%d",*(ptr + 4));
return 0;
A. 5
B. 11
C. 13
D. 7
Option: B
Explanation
Here a pointer variable ptr holds the address of a first value (2) of an object cr, then the address of
the pointer variable is incremented by 4 and then its value is displayed .
9. #include<stdio.h>
int main(){
int a = 25, b;
ptr = &a;
ptr1 = &b;
b = 36;
return 0;
}
A. 25 45632845
C. Compilation Error
D. 25 36
Option: D
Explanation
ptr holds the address of a variable A and ptr1 holds the address of a variable B . The value ofA is 25
and B is 36.
10. #include<stdio.h>
int main(){
int * ptr ;
printf("%d", sizeof(ptr));
return 0;
A. 4
B. 8
C. 2
D. compilation error
Option: A
Explanation
11. #include<stdio.h>
int main()
char temp;
printf("%d\n", temp);
return 0;
A. 2
B. 3
C. 4
D. 5
Option: C
Explanation
Here,temp=(arr+ 1)[2];
Let us consider the address of first element in an array arr[10] is 2293416 then temp looks like this
temp = (2293416 + 1)[2];
Now temp =(2293420)[2];, which denotes temp = "index value of 2 from the address 2293420(value =
2)";
Now temp = 4;(address = 2293428)
Thus the program outputted 4.
12. #include<stdio.h>
int main()
a[0][1][2] = 5;
printf("%d",*(*(*(a+0)+1)+2));
return 0;
A. printf("%d",*(((a+0)+1)+2));
B. printf("%d",*(*(*(a+0)+1)+2));
C. printf("%d",***((a+0)+1)+2);
Option: B
Explanation
Simply, this is a format for naviting to a value using the address of a first element in an array.
13. #include<stdio.h>
void fun(char**);
int main()
fun(arr);
return 0;
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
A. mat
B. fat
C. hat
D. cat
Option: C
Explanation
fun(arr) returns the address of first element in an array arr Let we start from the function void fun().
*t is a pointer variable which holds t = (p += sizeof(int))[-1];
ie ) t = (p = p + sizeof(int)) [-1];
t = (p = p + 4) [-1];
t = (p = address of bat + 4)[-1];
let us consider a address of bat is 2293416,
t = (p = 2293416 + 4)[-1];
t = (p = 2293432)[-1]
t = ("mat")[-1]; // index from "mat"
t = "hat";
thus hat is outputted.
14. #include<stdio.h>
int main()
return 0;
A. 0
B. Compilation error
C. 1
D. 4
Option: C
Explanation
printf("%d", (&arr+1 - &arr)); let us consider the address of an array arr starts from 2293420
then, printf("%d", (2293420 +1 - 2293420);
printf("%d", 0 + 1);
printf("%d", 1);
Thus 1 is outputted.
15. #include<stdio.h>
int main(){
i = j = k = 00;
for(i = 0;i<rows;i++)
for(j = 0;j<colums;j++)
if(a[k][j]<k)
k = a[i][j];
printf("%d\n", k);
return 0;
A. 00
B. No output
C. 0
D. 7
Option: C
Explanation
Initially we set i = 0, j = 0, k = 0. zero be never greater than any integer values in an array a[3][4], thus
if condition fails. and 0 is outputted.
16. #include<stdio.h>
int main()
for(j = 0;j<5;j++)
++ptr;
A. 2 2 2 2 2
B. 1 1 1 1 1
C. 1 2 3 4 5
Option: B
Explanation
Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr.
So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.
17. #include<stdio.h>
int main()
int i = 0;
printf("Hello");
for(i = 0;i<4;i++){
printf("%c", s[i]);
}
return 0;
A. Hello
B. Compilation error
C. Hell
Option: C
Explanation
18. #include<stdio.h>
int main()
int i = 0;
for(i = 0;i<4;i++)
printf("%c", s[i]);
return 0;
A. \0 \0 \0
B. \0 \0 \0 \0
C. No output
Option: C
Explanation
19. #include<stdio.h>
int main()
p = &s[3];
str = p;
str1 = s;
return 0;
A. 76
B. 77
C. 78
D. 79
Option: B
Explanation
p = &s[3].
i.e) p = address of '\n';
str = p;
i.e) str = address of p;
str1 = s;
str1 = address of 'a';
printf ("%d", ++*p + ++*str1 - 32);
i.e) printf("%d", ++\n + a -32);
i.e) printf("%d", 12 + 97 -32);
i.e) printf("%d", 12 + 65);
i.e) printf("%d", 77);
Thus 77 is outputted.
20. #include<stdio.h>
int main()
{
int i = 0;
printf("Hello");
for(i = 0;i<4;i++)
printf("%c", s[i]);
return 0;
A. Hello
B. Hell
C. No output
D. Compilation error
Option: C
Explanation
21. #include<stdio.h>
int main()
printf("%d", arr[3]);
return 0;
A. 3
B. 4
Option: C
Explanation
Here the size of an array is 2, but the value inside array is exceed 2. Thus it prints garbage value for
index more than 1
22. #include<stdio.h>
int main()
ptr = &arr;
ptr1 = *ptr + 3;
A. 1--11
B. 1-7
C. 1--4
D. 1--some address
Option: C
Explanation
23. #include<stdio.h>
int main()
int arr[5] = { 1, 3, 5, 7, 11 };
int *ptr;
ptr = &arr;
A. 1
B. 2
C. 3
D. Runtime error
Option: B
Explanation
24.#include <stdio.h>
int main()
int count=0;
var[++count]=++count;
for(count=0;count<5;count++)
printf("%d ",var[count]);
return 0;
A.0 1 0 0 0
B.0 2 0 0 0
C.0 0 2 0 0
D.0 0 0 0 0
Option C
25)
#include "stdio.h"
int main()
*ppp++; // Line 1
OPTIONS:
a)C B
b)B A
c)B C
d)C A
OUTPUT: (d) C A
Explanation:
Line 1 : Now, ppp points to next memory location i.e., index 1 of the character array.
Line 2 : Firstly, –*ppp= –(*ppp) is executed and hence the value ‘B’ (which is in the index 1 position of
the char[] array) gets decremented by 1(i.e., it becomes ‘A’)and it is sent for printing. Then *++ppp=
*(++ppp) is executed which initially increments the pointer to the next element of the array and prints
the value in that index number 2 which is ‘C’. Although –*ppp is executed first compared to *++ppp,
the display will be shown in the order as we mentioned in the printf() function in line 2. Hence we get
output as C A.
1.#include<stdio.h>
#include<conio.h>
int main()
{printf("%c\n",7["pointerofc"] );
getch();
return 0;
}
o/p:o
2.#include<stdio.h>
int main(){
{}
// ; without using ;
// using if statement
#include <stdio.h>
int main()
if (printf("%c\n", 59))
if (putchar(59))
return 0;
4. #include "stdio.h"
int main()
void *pVoid;
pVoid = (void*)0;
printf("%lu",sizeof(pVoid));
return 0;
}
Pick the best statement for the above C program snippet.
(A) Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no
compile error but it’ll result in run time error.
(B) Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t
assigned to any pointer. That’s why it’ll result in compile error.
(C) No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal to
size of int.
(D) sizeof() operator isn’t defined for a pointer of void type.
5. Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes
(i.e. typical case)
char *pChar;
int *pInt;
float *pFloat;
sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);
a.444
b.144
c.148
d.none
ans:a
6. #include "stdio.h"
void fun(int n)
int idx;
int arr2[n];
for (idx=0; idx<n; idx++)
arr2[idx] = 0;
int main()
fun(4);
return 0;
Definition of both arr1 and arr2 is incorrect because variable is used to specify the size of array. That’s
why compile error.
(B) Apart from definition of arr1 arr2, initialization of arr1 is also incorrect. arr1 can’t be initialized due
to its size being specified as variable. That’s why compile error.
(C) Initialization of arr1 is incorrect. arr1 can’t be initialized due to its size being specified as variable.
That’s why compile error.
(D) No compile error. The program would define and initializes both arrays to ZERO.
Answer: (C)
7. Which of the followings is correct for a function definition along with storage-class specifier in C
language?
(A) int fun(auto int arg)
(B) int fun(static int arg)
(C) int fun(register int arg)
(D) int fun(extern int arg)
(E) All of the above are correct.
Answer: (C)
8. Suppose a, b, c and d are int variables. For ternary operator in C ( ? : ), pick the best statement.
(A) a>b ? : ; is valid statement i.e. 2nd and 3rd operands can be empty and they are implicitly replaced
with non-zero value at run-time.
(B) a>b ? c=10 : d=10; is valid statement. Based on the value of a and b, either c or d gets assigned the
value of 10.
(C) a>b ? (c=10,d=20) : (c=20,d=10); is valid statement. Based on the value of a and b, either
c=10,d=20 gets executed or c=20,d=10 gets executed.
(D) All of the above are valid statements for ternary operator.
Answer: (C)
9. int (*p)[5];
It will result in compile error because there shouldn’t be any parenthesis i.e. “int *p[5]” is valid.
(B) p is a pointer to 5 integers.
(C) p is a pointer to integer array.
(D) p is an array of 5 pointers to integers.
(E) p is a pointer to an array of 5 integers
Answer: (E)
double y = 2.17;
Which of the following is correct way for printing these variables via printf.
(A) printf(“%f %lf %Lf”,x,y,z);
(B) printf(“%f %f %f”,x,y,z);
(C) printf(“%f %ff %fff”,x,y,z);
(D) printf(“%f %lf %llf”,x,y,z);
Answer: (A)
1)
# include <stdio.h>
*ptr = 30;
}
int main()
int y = 20;
fun(&y);
printf("%d", y);
return 0;
Ans:30
2)
#include <stdio.h>
int main()
int *ptr;
int x;
ptr = &x;
*ptr = 0;
*ptr += 5;
(*ptr)++;
return 0;
Ans:x = 0
*ptr = 0
x=5
*ptr = 5
x=6
*ptr = 6
3)
#include<stdio.h>
int main()
(ptr2 - ptr1));
return 0;
Ans:Number of elements between two pointer are: 5. Number of bytes between two pointers are: 20
4)
#include <stdio.h>
int main()
return 0;
}
Ans:90.500000 3
5)
#include<stdio.h>
int main()
int a;
char *x;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%dn",a);
return 0;
Ans:Machine dependent
6)
int main()
printf("%cn", *&*&*ptr);
return 0;
Ans: G
7)
#include<stdio.h>
int i;
int main()
int i;
fun(arr);
return 0;
Ans:Machine Dependent
8)
#include<stdio.h>
p = q;
*p = 2;
int i = 0, j = 1;
int main()
f(&i, &j);
getchar();
return 0;
Ans: 0 2
9)
int y, z;
**ppz += 1;
z = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
void main()
c = 4;
b = &c;
a = &b;
return 0;
ans: 19
10)
#include<stdio.h>
int main()
int a = 12;
printf("%d", *ptr);
getchar();
return 0;
}
ans:Compiler error
11)
#include<stdio.h>
char *t = x;
x = y;
y = t;
int main()
char *x = "geeksquiz";
char *y = "geeksforgeeks";
char *t;
swap(x, y);
t = x;
x = y;
y = t;
return 0;
Ans:(geeksquiz, geeksforgeeks)
(geeksforgeeks, geeksquiz)
12)
#include <stdio.h>
int main()
{
int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
++*p;
p += 2;
printf("%d", *p);
return 0;
Ans: 3
13)
#include <stdio.h>
void f(char**);
int main()
f(argv);
return 0;
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
ans: gh
14)
int ( * f) (int * ) ;
ans:A pointer to a function that takes an integer pointer as argument and returns an integer.
15)
#include <stdio.h>
int x;
void Q(int z)
z += x;
print(z);
int x = *y + 2;
Q(x);
*y = x - 1;
print(x);
main(void)
x = 5;
P(&x);
print(x);
ans: 12 7 6
16)
char *pChar;
int *pInt;
float *pFloat;
sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);
ans: 4 4 4
17)
In the below statement, ptr1 and ptr2 are uninitialized pointers to int i.e. they are pointing to some
random address that may or may not be valid address.
ans:false
18)
#include <stdio.h>
int main()
*ptr = 5;
return 0;
ans:Compile error
19)#include<stdio.h>
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
int main()
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf("%dn", a);
ans: 2016
20)
m = m + 5;
*p = *p + m;
return;
void main()
f(&i, j);
printf("%d", i+j);
ans:30
21)
int main()
int array[5][5];
return 0;
ans:1
22)
int main()
*++b = 2;
printf("%d ",a);
return 0;
ans:556
23)
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
printf("%d,%d", x, y);
ans:1,0
24)
# include <stdio.h>
void fun(int x)
x = 30;
int main()
{
int y = 20;
fun(y);
printf("%d", y);
return 0;
ans:20
25)
Faster access to non-local variables is achieved using an array of pointers to activation records, called
a
ans:activation tree
#include <stdio.h>
int main()
int MAX=10;
int array[MAX];
return 0;
1. size of array is = 20
2. size of array is = 40
3. size of array is = 4
4. Error
ans:2
#define MAX 10
int main()
{ int array[MAX]={1,2,3},tally;
for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)
printf("%d ",*(tally+array));
return 0;
1. Error
2. 1 3 4 5 6 7 8 9 10 11
3. 1 2 3 0 0 0 0 0 0 0
4. 0 0 0 0 0 0 0 0 0 0
Ans:3
#include <stdio.h>
int main()
printf("%d...%d",*array,*(array+3)* *array);
return 0;
1. Error
2. 10...40
3. 10...300
4. 10....400
Ans:4
Explanation:
#include <stdio.h>
int main()
printf("%c,%c,%c\n",*(x+tally)+1,x[tally]+1,*(tally+x)+1);
return 0;
1. Error
2. A,A,A
B,B,B
C,C,C
D,D,D
E,E,E
3. B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
4. E,E,E
D,D,D
C,C,C
B,B,B
A,A,A
Ans: 3
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
5.Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is
100. What is the address of A[11, 5] ? Assume row major storage.
1. 560
2. 565
3. 570
4. 575
Ans:1
1. Type COLONGE : (LIME, PINE, MUSK, MENTHOL); var a : array [COLONGE] of REAL;
7.A three dimensional array in ‘C’ is declared as int A[x][y][z]. Here, the address of an item at the
location A[p][q][r] can be computed as follows (where w is the word length of an integer):
1. &A[0][0][0] + w(y * z * q + z * p + r)
3. &A[0][0][0] + w(x * y * p + z * q+ r)
4. &A[0][0][0] + w(x * y * q + z * p + r)
Ans:2
8.What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
1. ((((a+i)+j)+k)+l)
2. *(*(*(*(a+i)+j)+k)+l)
3. (((a+i)+j)+k+l)
4. ((a+i)+j+k+l)
Ans:2
9.Which of the following operations is not O(1) for an array of sorted data. You may assume that array
elements are distinct.
2. Delete an element
# include <stdio.h>
void fun(int x)
x = 30;
int main()
int y = 20;
fun(y);
printf("%d", y);
return 0;
1. 30
2. 20
3. Compiler Error
4. Runtime Error
Ans:2
#include<stdio.h>
int main()
{
int a;
char *x;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d\n",a);
return 0;
1. Machine dependent
2. 513
3. 258
4. Compiler Error
ans:1
12.What is (void*)0?
3. Error
4. None of above
ans:1
1. stdio.h
2. stddef.h
4. math.h
Ans:3
The macro "NULL" is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.
14.How many bytes are occupied by near, far and huge pointers (DOS)?
Ans:1
near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4
bytes long
15.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?
1. .
2. &
3. *
4. ->
Ans:4
1. *
2. &
3. &&
4. ||
Ans:1
17.Point out the compile time error in the program given below.
#include<stdio.h>
int main()
int *x;
*x=100;
return 0;
3. No error
4. None of above
Ans:3
Explanation:
While reading the code there is no error, but upon running the program having an unitialised
variable can cause the program to crash (Null pointer assignment).
18.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?
Explanation:
If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct
answer. But the modern compilers will take care of this kind of errors.
int (*ptr)[10];
Ans:2
20.In C, if you pass an array as an argument to a function, what actually gets passed?
Ans:3
21.Which of the following statements are correct about 6 used in the program?
int num[6];
num[6]=21;
1. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a type.
2. In the first statement 6 specifies a array size, whereas in the second statement it specifies a
particular element of array.
3. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a array size.
Ans:2
Explanation:
The statement 'B' is correct, because int num[6]; specifies the size of array and num[6]=21;
designates the particular element(7th element) of the array.
2: The expression num[1] designates the very first element in the array.
A. 1
B. 1,4
C. 2,3
D. 2,4
Ans: B
Explanation:
1. The array int num[26]; can store 26 elements. This statement is true.
2. The expression num[1] designates the very first element in the array. This statement is false,
because it designates the second element of the array.
3. It is necessary to initialize the array at the time of declaration. This statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO
just replaces the symbol SIZE with given value.
1. True
2. False
Ans:1
Explanation:
Yes, It is possible to allocate a block of memory (of arbitrary size) at run-time, using the standard
library's malloc function, and treat it as an array.
24.What is (void*)0?
3. Error
4. None of above
Ans:1
int main()
{
return 0;
}
1. hello
2. ello
3. hi
4. ello hi
ans:3
#include <stdio.h>
int main()
{
printf("%d", sizeof(a));
return 0;
}
1. 9
2. 12
3. 8
4. 10
ans:2
1. Predefined size
3. Faster Access
ans:4
ans:3
2. 2 works, 1 doesn’t
ans:4
1. Variable
2. Array
3. Structures
ans:2
31. Which of the following is the correct syntax to send an array as a parameter to function?
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);
ans: a
#include <stdio.h>
int main()
{
int i = 10;
foo(&p);
printf("%d\n", *p);
}
{
int j = 11;
*p = &j;
printf("%d\n", **p);
}
a) 11 11
b) Undefined behaviour
d) Segmentation fault/code-crash
ans: a
#include <stdio.h>
int main()
{
foo(&i);
{
int j = 2;
p = &j;
}
a) 2 97
b) 2 2
ans: a
#include <stdio.h>
void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
}
{
printf("%d\n", *p);
}
a) 10
ans: c
#include <stdio.h>
struct p
{
int x;
char y;
};
int main()
{
printf("%d\n", ptr1->x);
else
printf("falsen");
}
b) 1
c) Undefined behaviour
d) false
ans: d
#include <stdio.h>
struct p
{
int x;
char y;
};
int main()
{
printf("%d\n", ptr1->x);
}
b) 1
c) Undefined behaviour
d) Segmentation fault
ans: d
void main()
{
int k = 5;
int *p = &k;
}
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
ans: a
c) The conventional rectangular subscript calculation 20 * row + col is used to find the element a[row,
col].
ans: d
a) The definition only allocates 10 pointers and does not initialize them
b) Initialization must be done explicitly
c) The definition only allocates 10 pointers and does not initialize them & Initialization must be done
explicitly
d) Error
ans: c
#include <stdio.h>
void main()
{
printf("%s", a[2]);
}
a) fellows
b) fellow
c) fello
d) fell
ans: c
#include <stdio.h>
int main()
{
return 0;
}
b) hello
c) Undefined behaviour
d) hellon
ans: c
ans: c
#include <stdio.h>
struct point
{
int x;
int y;
};
int main()
{
foo(p1);
}
{
printf("%d\n", p[1].x);
}
b) 3
c) 2
d) 1
ans: b
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
a) 2
b) 4
c) 16
d) 8
ans: d
#include <stdio.h>
int main()
{
int i = 0, j = 1;
printf("%d", (*a)[0]);
return 0;
}
b) Undefined behaviour
c) 0
ans: c
46.Pointer of stack, is always set to
ans : a
47.To set array[i] to 0, we must first get its address, start by multiplying i with
a)0
b)1
c)2
d)4
ans: d
char **argv;
ans: b
49. What do the following declaration signify?
int (*pf)();
a) pf is a pointer to function.
b) pf is a function pointer.
ans: c
#include<stdio.h>
int main(){
ptr = &array[1];
ptr1 = ptr + 3;
*ptr1 = 101;
printf("%c", *ptr++);
return 0;
a) not
b) Knot
c) note
d)garbage value
ans: c
Explanation:
In the above program, we assigned the starting value of pointer variable is with the address of second
element in an array i.e) Knot. Then we append the value 101 i.e)'e' to the ptr variable. Thus it prints
note
1)
#include<stdio.h>
#include<conio.h>
int main()
ptr1 = &num ;
ptr2 = ptr1 + 2 ;
clrscr();
printf("%d",ptr2 - ptr1);
getch();
return(0);
Output :
2) #include<stdio.h>
int main()
return 0;
}
o/p:3 1 3
3) void main()
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++)
++q;
for(j=0;j<5;j++)
printf(" %d ",*p);
++p;
o/p:
22222
23465
4) #include<stdio.h>
#include <conio.h>
void main()
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
clrscr();
printf("%d",++*p + ++*str1-32);
getch();
o/p:77
5)
#include<stdio.h>
#include <conio.h>
void main()
int *p,*q;
p=&a[2][2][2];
*q=***a;
clrscr();
printf("%d----%d",*p,*q);
getch();
o/p:0----10
6) #include <stdio.h>
#include <conio.h>
void main( )
int **ptr = p;
ptr++;
clrscr();
*++ptr;
++*ptr;
getch();
o/p:1 1 1
2 2 2
3 3 3
3 4 4
7)
#include <stdio.h>
#include <conio.h>
void main( )
p = ptr;
**++p;
clrscr();
printf(“%s”,*--*++p + 3);
getch();
o/p:ck
8)
#include <stdio.h>
#include <conio.h>
void main()
int i = 257;
clrscr();
getch();
o/p:1 1
9)
#include<stdio.h>
#include <conio.h>
int main()
p = &arr[1][1][1];
q = (int*) arr;
clrscr();
getch();
return 0;
o/p:8,10
10)
#include<stdio.h>
#include <conio.h>
int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
clrscr();
getch();
return 0;
Output :
1006, 2, 2
11)
#include <stdio.h>
int main()
{
int *p = ary + 3;
printf("%d\n", p[-2]);
}
o/p:
12) #include<stdio.h>
int main()
y = &x;
z = y;
*y++;
*z++;
x++;
return 0;
int main()
*ppp++; // Line 1
}
o/p:C A
14) main()
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
Answer:
45545
15)
#include<stdio.h>
#include<conio.h>
void main()
printf("%d",++(*p)); Line 6
Output :
16)
void main()
char s[ ]="man";
int i;
for(i=0;s[ i];i++)
printf("\n%c%c%c%c",s[i],*(s+i),*(i+s),i[s]);
Output :
mmmm
aaaa
nnnn
17)
#include <stdio.h>
#include <conio.h>
void main()
void *v;
int integer=2;
int *i=&integer;
v=i;
printf("%d",(int*)*v);
o/p:error
18)
void main()
int a[10];
clrscr();
printf("%d",*a+1-*a+3);
getch();
Output :
19)
#include <stdio.h>
#include <conio.h>
void main()
{
char p[ ]="%d\n";
p[1] = 'c';
clrscr();
printf(p,65);
getch();
Output :
20)
#include <stdio.h>
#include <conio.h>
void main()
int a=2,*f1,*f2;
f1 = f2 = &a;
clrscr();
printf("\n%d %d %d",a,*f1,*f2);
getch();
Output :
16 16 16
21)
#include <stdio.h>
#include <conio.h>
void main()
int i=300;
char *ptr = &i;
*++ptr=2;
clrscr();
printf("%d",i);
getch();
Output :
556
22)
#include <stdio.h>
#include <conio.h
void main()
while (*ptr++)
least = *ptr;
clrscr();
printf("%d",least);
getch();
Output :
23)
#include <stdio.h>
#include <conio.h>
void main()
clrscr();
printf(“%d”,k);
getch();
Output :
Error
24)
#include <stdio.h>
#include <conio.h>
void main(){
int *ptr;
clrscr();
printf("%d",*ptr);
getch();
Output : 0
25)
#include <stdio.h>
#include <conio.h>
void main()
int a=10,*j;
void *k;
j=k=&a;
j++;
k++; Line 10
printf("\n %u %u ",j,k);
Output :
error
QUESTIONS
#include<stdio.h>
int main()
{
int a[] = { 1, 2, 3, 4, 5} ;
int *ptr;
ptr = a;
return 0;
}
output
2
#include<stdio.h>
int main()
y = &x;
z = y;
*y++;
*z++;
x++;
return 0;
Output:
3. What is (void*)0?
C. Error
ANS:C
4.What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
A. ((((a+i)+j)+k)+l)
B. *(*(*(*(a+i)+j)+k)+l)
C. (((a+i)+j)+k+l)
D. ((a+i)+j+k+l)
ANS:B
A. *
B. &
C. &&
D. ||
ANS:A
6.Point out the compile time error in the program given below.
#include<stdio.h>
int main()
int *x;
*x=100;
return 0;
C. No error
#include<stdio.h>
int main()
int j;
{
printf("%d\n", a);
a++;
}
return 0;
ANS:C
8.#include<stdio.h>
int main()
p = ptr;
++p;
printf("%s", **p+1);
return 0;
A. ink
B. ack
C. ite
D. let
ANS:A
9.What will be the output of the program If the integer is 4bytes long?
#include<stdio.h>
int main()
p = &i;
q = &p;
r = &q;
return 0;
A. 8, 8, 8
ANS:A
10.A pointer is
ANS:C
A. True
B. False
ANS:B
#include<stdio.h>
int main()
return 0;
A. True
B. False
ANS:A
13.The following program reports an error on compilation.
#include<stdio.h>
int main()
void *k;
k=&i;
j=k;
printf("%f\n", *j);
return 0;
A. True
B. False
ANS:B
14.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?
ANS:C
int (*ptr)[10];
A. ptr is array of pointers to 10 integers
ANS:B
16.In C, if you pass an array as an argument to a function, what actually gets passed?
ANS:C
#include<stdio.h>
int main()
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
return 0;
A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20
ANS:C
#include<stdio.h>
int main()
int i, j;
{
{
*(*(i+p)+j), *(*(p+j)+i));
}
}
return 0;
A. 1, 1, 1, 1
2, 3, 2, 3
3, 2, 3, 2
4, 4, 4, 4
B. 1, 2, 1, 2
2, 3, 2, 3
3, 4, 3, 4
4, 2, 4, 2
C. 1, 1, 1, 1
2, 2, 2, 2
2, 2, 2, 2
3, 3, 3, 3
D. 1, 2, 3, 4
2, 3, 4, 1
3, 4, 1, 2
4, 1, 2, 3
ANS:C
#include<stdio.h>
int main()
int *ptr;
ptr = &a[0][0];
fun(&ptr);
return 0;
printf("%d\n", **p);
}
A. 1
B. 2
C. 3
D. 4
ANS:A
20.What will be the output of the program if the array begins 1200 in memory?
#include<stdio.h>
int main()
return 0;
ANS:B
#include<stdio.h>
int main()
{
int arr[1]={10};
printf("%d\n", 0[arr]);
return 0;
A. 1
B. 10
C. 0
D. 6
ANS:B
22.What will be the output of the program if the array begins at address 65486?
#include<stdio.h>
int main()
return 0;
A. 65486, 65488
B. 65486, 65486
C. 65486, 65490
D. 65486, 65487
ANS:B
#include<stdio.h>
int main()
printf("%d\n", sizeof(arr)/sizeof(arr[0]));
return 0;
A. 5
B. 4
C. 6
D. 7
ANS:B
24.Which of the following statements mentioning the name of the array begins DOES NOT yield the
base address?
A. A
B. A, B
C. B
D. B, D
ANS:B
2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration.
A. 1
B. 1,4
C. 2,3
D. 2,4
ANS:B
#include<stdio.h>
int main()
p = ptr;
++p;
printf("%s", **p+1);
return 0;
A. ink
B. ack
C. ite
D. let
#include<stdio.h>
int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
A. 30
B. 27
C. 9
D. 3
#include<stdio.h>
int main()
z=y;
*y++=*z++;
x++;
return 0;
#include<stdio.h>
int main()
*p='M';
printf("%s\n", str);
return 0;
A. Mello
B. Hello
C. HMello
D. MHello
5.What will be the output of the program If the integer is 4bytes long?
#include<stdio.h>
int main()
p = &i;
q = &p;
r = &q;
return 0;
A. 8, 8, 8
6.Point out the compile time error in the program given below.
#include<stdio.h>
int main()
int *x;
*x=100;
return 0;
C. No error
D. None of above
#include<stdio.h>
int main()
int j;
{
printf("%d\n", a);
a++;
}
return 0;
}
8.What is (void*)0?
C. Error
D. None of above
char *p;
p = (char*) malloc(100);
A. char p = *malloc(100);
C. char *p = (char*)malloc(100);
10.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. ->
11.A pointer is
A. *
B. &
C. &&
D. ||
13.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?
int (*ptr)[10];
15.In C, if you pass an array as an argument to a function, what actually gets passed?
#include<stdio.h>
int main()
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
return 0;
A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20
17.What will be the output of the program if the array begins at 65472 and each integer occupies 2
bytes?
#include<stdio.h>
int main()
return 0;
A. 65474, 65476
B. 65480, 65496
C. 65480, 65488
D. 65474, 65488
#include<stdio.h>
int main()
int arr[1]={10};
printf("%d\n", 0[arr]);
return 0;
A. 1
B. 10
C. 0
D. 6
19.Which of the following statements mentioning the name of the array begins DOES NOT yield the
base address?
A. A
B. A, B
C. B
D. B, D
20.Which of the following statements are correct about 6 used in the program?
int num[6];
num[6]=21;
A. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a type.
B. In the first statement 6 specifies a array size, whereas in the second statement it specifies a
particular element of array.
C. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a array size.
2: The expression num[1] designates the very first element in the array.
A. 1
B. 1,4
C. 2,3
D. 2,4
23.If a is an array of 5 integers then which of the following is the correct way to increase its size to 10
elements?
int[] a = int[10];
a.Length = 10 ;
a.GetUpperBound(10);
24.Which of the following are the correct ways to define an array of 2 rows and 3 columns?
int[ , ] a;
int[ , ] a;
int[ , ] a;
int[ , ] a;
A. 1, 2 , 3
B. 1, 3
C. 2, 3
D. 2, 4, 5
E. 4, 5
25.Which of the following is the correct way to obtain the number of elements present in the array
given below?
intMyArr.GetMax;
intMyArr.Highest(0);
intMyArr.GetUpperBound(0);
intMyArr.Length;
intMyArr.GetMaxElements(0);
A. 1, 2
B. 3, 4
C. 3, 5
D. 1, 5
E. 4, 5
#include <stdio.h>
void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
{
printf("%d\n", *p);
}
a)10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
#include <stdio.h>
void foo(int*);
int main()
{
foo(p++);
{
printf("%d\n", *p);
}
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
#include <stdio.h>
int main()
{
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}
a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
#include <stdio.h>
int main()
{
foo(&i);
printf("%d ", *p);
}
{
int j = 2;
p = &j;
}
a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
foo(&p);
return 0;
}
int j = 2;
*p = &j;
}
a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
#include <stdio.h>
int main()
{
int i = 11;
int *p = &i;
foo(&p);
}
{
int j = 10;
*p = &j;
#include <stdio.h>
int main()
{
int i = 10;
int *p = &i;
foo(&p);
{
int j = 11;
*p = &j;
}
a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash
1. Write a program to give the following output for the given input
Eg:Input: a1b10
Output:abbbbbbbbbb
Input:a3b1c5
Output:aaabccccc
2.Write a program to delete all vowels from a sentence.Assume that the sentence is not more than 80 characters long.
4.Print all nodes of a given binary tree using inorder traversal without recursion?
10.C program to find the largest number using dynamic memory allocation.
12.AAAAA
BBBB
CCC
DD
E
13.1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
14 . 55555
45555
34555
23455
12345
15. 1 2 3 4 5
6 7 8 9
10 11 12
13 14
15
16. 1 1
2 2
3 3
4 4
5
4 4
3 3
2 2
1 1
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********