Objective questions of c



Objective type questions on c with answers for interview 
C programming language objective questions and answers

(1)
#define max value 10
int main(){
    int a=60;
    if(a/max value==6)
         printf("equal");
    else
         printf("not equal");
return 0;
}

What will be output if you compile and execute the above code?
(a)equal
(b)not equal
(c)Run time error
(d)Compiler error

(2)
#define num int long
int main(){
    num a=0;
    printf("%d,%d,%d",a++,sizeof a++,sizeof(a++));
    return 0;
}

What will be output if you compile and execute the above code?
(a)3 2 4
(b)0 0 4
(c)0 4 4
(d)Compiler error

(3)
#define short int long
int main(){
    printf("%d",sizeof(short));
    return 0;

   
}

What will be output if you compile and execute the above code?
(a)2
(b)4
(c)8
(d)Compiler error

(4)
#define float char
int main(){       
float f=255;
    printf("%d",sizeof(f++));
return 0;
}

What will be output if you compile and execute the above code?
(a)1
(b)2
(c)8
(d)Compiler error

(5)
int main(){      
char f=255.0;
    printf("%d",sizeof(f++));
return 0;
}

What will be output if you compile and execute the above code?
(a)1
(b)8
(c)10
(d)Compiler error

(6)
int main(){       
char f=255;
    f++;
    printf("%d",sizeof(f));
return 0;
}

What will be output if you compile and execute the above code?
(a)1
(b)2
(c)4
(d)Compiler error

(7)
#define value 10\2
int main(){
printf("%d",value);
return 0;
}

What will be output if you compile and execute the above code?
(a)5
(b)20
(c)102
(d)Compiler error

(8)
#define xxx 11\
3
int main(){
    printf("%ld",xxx);
    return 0;
}

What will be output if you compile and execute the above code?
(a)11
(b)3
(c)113
(d)Compiler error

(9)
#define option1 a++; printf("%d",a);
#define option2 print("%d",a);
int main(){
    int a=10;
    if(a++)
         option1
    else
         option2; 
}

What will be output if you compile and execute the above code?
(a)10
(b)11
(c)12
(d)Compiler error

(10)
//test.c
int main(){
    printf("%s",__FILE__);
}

What will be output if you compile and execute the above code?
(a)null
(b)test.c
(c)url of current working directory
(d)Compiler error

(11)
#include"stdio.h"
int main(){
    #ifdef __stdio_h
         prinrf("defined");
    #else
         printf("not defined");
    #endif
return 0;
}

What will be output if you compile and execute the above code?
(a) defined
(b) not defined
(c)Run time error
(d)Compiler error

(12)
#include"stdio.h"
int main(){
    const int a=1;
   
    #if 5+~5+1
         printf("%d",a+1);
    #elif 7
         printf("%d",a+2);
    #else
         printf("%d",a+3);
    #endif
return 0;   
}

What will be output if you compile and execute the above code?
(a)2
(b)3
(c)4
(d)Compiler error

(13)
#define conio.h
#include "stdio.h"
#define max 0\5
int main(){
    #ifndef __conio_h
    #define conio.h
    printf("%s",__TIME__);
    #else
    #undef __conio_h
    printf("%s",__DATE__);
    #endif
return 0;   
}

What will be output if you compile and execute the above code?
(a)Output will be date of compilation
(b)Output will be time of compilation
(c)Output will be both time of compilation and date of compilation
(d)Compiler error

(14)
#define max 5
#define a max*max
#define value a\a
int main(){
    const int aa=5;
    printf("%d",value+aa);
return 0;
}

What will be output if you compile and execute the above code?
(a)5
(b)6
(c)10
(d)Compiler error

(15)
#define function(a,b) a##b
int main(){
    printf("%d",function(5,2));
    return 0;
}

What will be output if you compile and execute the above code?
(a)10
(b)2
(c)52
(d)Compiler error

(16)
#define find(a,b,c) #a#b#c
int main(){
    int a=10;
    int b=20;
    int c=30;
    printf("%s",find(a,b,c)+1);
return 0;
}

What will be output if you compile and execute the above code?
(a)102030
(b)02030
(c)bc
(d)Compiler error

(17)
#define swap(x,y) x^=y^=x^=y
int main(){
    int a=10,b=20;
    swap(a,b);
    printf("%d %d" ,a,b);
    return 0;
}

What will be output if you compile and execute the above code?
(a)10 20
(b)20 10
(c)0 10
(d)Compiler error

(18)
#define int long
#define cal(x,y,z) x*y*z
int main(){
    int a=2;
    int b=cal(a++,a++,a++);
    printf("%d,%d" ,a,b);
    return 0;
}

What will be output if you compile and execute the above code?
(a)5,0
(b)5,125
(c)5,60
(d)Compiler error

(19)
#define final(a,b,c) ++a+ ++b+ ++c
int main(){
    printf("%d" ,final(1,2,3));
    return 0;
}

What will be output if you compile and execute the above code?
(a)6
(b)9
(c)10
(d)Compiler error

(20)
void one();
void two();
#pragma startup one 2
#pragma startup two 1
int main(){
    printf("main ");
return 0;
}
void one()
{
    printf("one ");
}
void two()
{
    printf("two ");
}

What will be output if you compile and execute the above code?
(a)main one two
(b)one main two
(c)main
(d)two main one

Answer of c programming objective types questions and answers

1.     (d)
2.     (c)
3.     (b)
4.     (a)
5.     (a)
6.     (a)
7.     (c)
8.     (c)
9.     (d)
10.    (b)
11.    (b)
12.    (b)
13.    (b)
14.    (c)
15.    (c)
16.    (c)
17.    (b)
18.    (a)
19.    (d)
20.    (d)

9 comments:

Anonymous said...

Please explain the answer of all the question. Manish Srivastava

Anonymous said...

plese send the explanation of the answer at my id manishsri.2604@rediffmail.com

Anonymous said...

#define swap(x,y) x^=y^=x^=y
int main(){
int a=10,b=20;
swap(a,b);
printf("%d %d" ,a,b);
return 0;
}
please explain the answer of this question

Anonymous said...

please send the explanation on pgoyal1512@gmail.com

Anonymous said...

pls send the explanation on aarthisri2009@gmail.com

Unknown said...

pls send the explanation on chandrakanthr09@gmail.com

Anonymous said...

#define directive is also called as Macro substitution directive
Task of macro substitution directive is to replace the identifier with corresponding Token_string.
so swap(a,b) is replaced by x = x^y, y = x^y, x = x^y;

Unknown said...

please explain the answer of the above question and if u r willing to send explanation please send over vinayvidhani@hotmail.com

Unknown said...

1 wrong answer should be equal