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) What will be the output of the program below
#include
main(){
int num[] = {1,4,8,12,16};
int *p,*q;
int i;
p = num;
q = num+2;
i = *p++;
printf("%d, %d, %d\n",i, *p, *q);
}
Options a) 4, 4, 8 b) 1, 4, 8 c) 2, 1, 8 d) 2, 4, 8
#include
main(){
char *a[4]={"jaya","mahesh","chandra","swapant"};
int i = sizeof(a)/sizeof(char *);
printf("i = %d\n", i);
}
Options: a) 4 b) 7 c) 8 d) 1
Q3) What will be the output of the program below
#include
void fun(int *a, int *b)
{
int *t;
t=a;
a=b;
b=t;
}
main()
{
int a=2;
int b=3;
fun(&a,&b);
printf(%d, %d",a, b);
}
options: a) 3, 2 b) compilation error c) error at run time d) 2, 3 e) None of the above
Q4)
#include
#define scanf "%s is a string"
main()
{
printf(scanf,scanf);
}
Options: a) compilation error b) runtime error c) %s is a string %s is a string d) %s is a string is a string e) None of the above
Q5)
#includemain(){
int i =(2+3, 4
Options: a) 4 b) 1 c) 0 d) 5 e) Compilation error
#include
main(){
int i =0;
i = 2+3, 4>3, 3;
printf("%d", i);
}
Options: a) 0 b) 3 c) 5 d) 4 e) Compilation error
Q7)
#include
int main(){
char *p="abc";
char *q="abc123";
while(*p==*q)
{
printf("%c %c\n",*p,*q);
}
}
Options: a) aabbcc b) aabbcc112233 c) aabbcc123 d) Infinite Loop e) Segmentation fault
Q8)
#include
int main(){
char *p="abc";
char *q="abc123";
while(*p=*q)
{
printf("%c %c\n",*p,*q);
}
}
Options: a) aabbcc b) aabbcc112233 c) aabbcc123 d) Infinite Loop e) Segmentation fault
#include
main(){
printf("%u", -1);
}
Options: a) -1 b) 1 c) 65535 d)Compilation Error e) None of the above
#include
struct XX{
float 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




