10 Objective type interview questions with answers on C/C++
Before you start:-
- You can check your answer by filling a,b,c,d or e in the text box.
- You can get the answer by clicking Give Up Button.
Try yourself before giving up 🙂
Q1)
#include
struct XX{
int a:10;
int b:6;
char c;
} structure;
int main(){
int i = sizeof(structure);
printf("%d", i);
}
Options: a) 4 b) 8 c) 9 d) 3 e) Compilation error
Q2)
#include
#include
main()
{
char *s;
s="hot java";
strcpy(s,"solaris java");
printf("%s", s);
}
Options:a) hot java b) solaris java c) compilation error d) Segmentation fault
Q3) In below code snippet, How many time solaris will be printed?
#include
main()
{
int ret;
ret=fork();ret=fork();ret=fork();ret=fork();
if(!ret)
printf("sun");
else
printf("solaris");
}
Options: a) 16 b) 1 c) 8 d) 4
A program MIN takes integers as inline arguments and gives the smallest integer as output. What will be the value of argc if the program is invoked as “MIN 12 51 17 15” ?
Options: a) 4 b) 5 c) 1 d) 0
#include
int main(int argc, char ** argv)
{
int x;
scanf(“%d”,x);
printf(“%d”, x);
}
Options: a) print the integer value given as input b) Compilation error c) Run time error d) None of the above
#include
int main(int argc, char ** argv)
{
int x=7;
printf("%d", x++*x++);
}
Options: a) 56 b) 49 c) 72 d) 64
#include
#include
main(){
char string[10] = "abc";
strcat(string, 'd');
printf("%s", string);
}
Options: a) abc b) abcd c) d d) Compilation Error
include
int f(int *a)
{
int b =5;
a = &b;
}
main(){
int i =10;
printf("%d",i);
f(&i);
printf(",%d",i);
}
Options: a) 10,10 b) 10,5 c) Compilation error d) Runtime error
#include
void f(int i)
{
int j;
for (j=0;j<16;j++) { if (i & (0x8000>>j))
printf("1");
else
printf("0");
}
}
What is the purpose of the function ?
Options: a)prints hex representation of i b) prints decimal representation of i c) prints binary representation of i d) None
#include
#define f(a,b) a+b
#define g(a,b) a*b
main()
{
int m;
m=2*f(3,g(4,5));
printf("\n m is %d",m);
}
Options: a) 46 b) 70 c) 26 d) None of the above



