We have listed here some multiple choice questions with answers, which has asked by multiple companies like Oracle, Accenture, Infosys, TCS, Wipro etc.

You can prepare your job written and interview by using these sets of question from here.

1. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = 10;
void *p = &i;
printf(“%f\n”, *(float*)p);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) 10
d) 0.000000

Answer: d

2. What is the output of this C code?

#include <stdio.h>
int *f();
int main()
{
int *p = f();
printf(“%d\n”, *p);
}
int *f()
{
int j = 10;
return &j;
}
a) 10
b) Compile time error
c) Segmentation fault/runtime crash
d) Undefined behaviour

Answer: a

3. What is the output of this C code?

#include <stdio.h>
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

4. 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) You May or maynot change the value pointed by ptr
d) You can change the pointer as well as the value pointed by it

Answer: a

5. Which of the following does not initialize ptr to null (assuming variable declaration of a as int p;a=0;?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned

Answer: a

6. What is the output of this C code?

#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &x;
printf(“%p\n”, ptr);
ptr++;
printf(“%p\n “, ptr);
}
a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error

Answer: a

7. What is the output of this C code?

#include <stdio.h>
void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
}
void foo(int *p)
{
printf(“%d\n”, *p);
}
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash

Answer: c

8. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = 97, *p = &i;
foo(&p);
printf(“%d “, *p);
return 0;
}
void foo(int **p)
{
int j = 2;
*p = &j;
printf(“%d “, **p);
}
a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash

Answer: a

9. Which of the following can never be sent by call-by-value?
a) Variable
b) Array
c) Structures
d) Both Array and Structures

Answer: b

10. 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

Answer: c

11. What is the output of this C code?

#include <stdio.h>
void m(int p, int q)
{
int temp = p;
p = q;
q = temp;
}
void main()
{
int a = 6, b = 5;
m(a, b);
printf(“%d %d\n”, a, b);
}
a) 5 6
b) 5 5
c) 6 5
d) 6 6

Answer: c

12. What is the output of this C code?

#include <stdio.h>
void main()
{
char *s= “hello”;
char *p = s;
printf(“%c\t%c”, 1[p], s[1]);
}
a) h h
b) Run time error
c) l l
d) e e

Answer: d

13. What is the output of this C code?

#include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
printf(“%d\n”, *ary);
}
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable

Answer: a

14. Different ways to initialize an array with all elements as zero are

a) int array[5] = {};
b) int array[5] = {0};
c) int a = 0, b = 0, c = 0;
int array[5] = {a, b, c};
d) All of the mentioned

Answer: d

15. An array of similar data types which themselves are collection of dissimilar data type are
a) Linked Lists
b) Trees
c) Array of Structure
d) All of the mentioned

Answer: c

16. What is the output of the code given below?

#include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
int p[4];
p = ary;
printf(“%d\n”, p[1]);
}
a) 1
b) Compile time error
c) Undefined behaviour
d) 2

Answer: b

17. Comment on the output of this C code?

#include <stdio.h>
int main()
{
int *p = (int *)2;
int *q = (int *)3;
printf(“%d”, p + q);
}
a) 2
b) 3
c) 5
d) Compile time error

Answer: d

18. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8

Answer: c

19. What is the output of this C code?

#include <stdio.h>
void main()
{
char *s = “hello”;
char *p = s;
printf(“%c\t%c”, *p, s[1]);
}
a) e h
b) Compile time error
c) h h
d) h e

Answer: d

20. What is the output of this C code?

#include <stdio.h>
void main()
{
char *s = “hello”;
char *p = s * 3;
printf(“%c\t%c”, *p, s[1]);
}
a) h e
b) l e
c) Compile time error
d) l h

Answer: c

21. What is the output of this C code?

#include <stdio.h>
int main()
{
void *p;
int a[4] = {1, 2, 3, 4};
p = &a[3];
int *ptr = &a[2];
int n = (int*)p – ptr;
printf(“%d\n”, n);
}
a) 1
b) Compile time error
c) Segmentation fault
d) 4

Answer: a

22. What is the output of this C code?

#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
void *p = &a[1];
void *ptr = &a[2];
int n = 1;
n = ptr – p;
printf(“%d\n”, n);
}
a) 1
b) 4
c) Compile time error
d) Depends on the compiler

Answer: b

23. What is the output of this C code?

#include <stdio.h>
int main()
{
char *str = “hello world”;
char strc[] = “good morning india\n”;
strcpy(strc, str);
printf(“%s\n”, strc);
return 0;
}
a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour

Answer: a

24. What is the output of this C code?

#include <stdio.h>
int main()
{
char *str = “hello world”;
char strary[] = “hello world”;
printf(“%d %d\n”, sizeof(str), sizeof(strary));
return 0;
}
a) 11 11
b) 12 12
c) 4 12
d) 4 11

Answer: c

25. What is the output of this C code?

#include <stdio.h>
void fun(char *k)
{
printf(“%s”, k);
}
void main()
{
char s[] = “hello”;
fun(s);
}
a) hello
b) Run time error
c) Nothing
d) h

Answer: a