C Linux interview questions furthermore answers
(1)What will be output if you will execute following program by gcc compiler in Linux?#include
int main(){
int a=5;
printf("%d %d %d",a++,a++,++a);
return 0;
}
Output:
In LINUX GCC compiler
7 6 8
In TURBO C
7 6 6
Hints: In Turbo c parameter is passed from right toward left in printf function but not in the Linux.
(2)What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
int a=5,b=10,c=15,d=20;
printf("%d %d %d");
return 0;
}
Output:
In LINUX GCC compiler
Garbage values
In TURBO C
5 10 15
Hints: Local variables stores in the stack.
-->
(3) What will be output if you will execute following program by gcc compiler in Linux?
#include
int main(){
int i=5,j=5,y;
int x=++i + ++i + ++i;
y=++j + ++j + ++j;
printf("%d %d %d %d",x,y,i,j);
return 0;
}
Output:
In LINUX GCC compiler
22 22 8 8
In TURBO C
21 24 8 8
(4) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
int near *p;
int far *q;
int huge *r;
printf("%d %d %d",sizeof(p),sizeof(q),sizeof(r));
return 0;
}
Output:
In LINUX GCC compiler
Compilation error
In TURBO C
2 4 4
Note: In Linux there is not any concept regarding near, far furthermore huge pointers
(5) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
char *p;
int *q;
float **r;
printf("%d %d %d",sizeof(p),sizeof(q),sizeof(r));
return 0;
}
Output:
In LINUX GCC compiler
4 4 4
In TURBO C
2 2 2
Hints: size regarding any type regarding pointer in Linux is 4 furthermore in turbo c is 2.
(6) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
short int a=5;
int b=5;
long int c=5l;
float d=5.0f;
double e=5.0;
long double f=5.0L;
char g='5';
printf("Size regarding short int: %d\n",sizeof(a));
printf("Size regarding int: %d\n",sizeof(b));
printf("Size regarding long int: %d\n",sizeof(c));
printf("Size regarding float: %d\n",sizeof(d));
printf("Size regarding double: %d\n",sizeof(e));
printf("Size regarding long double: %d\n",sizeof(f));
printf("Size regarding char: %d\n",sizeof(g));
return 0;
}
Output:
In LINUX GCC compiler
Size regarding short int: 2
Size regarding int: 4
Size regarding long int: 4
Size regarding float: 4
Size regarding double: 8
Size regarding long double: 12
Size regarding char: 1
In TURBO C
Size regarding short int: 2
Size regarding int: 2
Size regarding long int: 4
Size regarding float: 4
Size regarding double: 8
Size regarding long double: 10
Size regarding char: 1
(7) What will be output if you will execute following program by gcc compiler in Linux?
#include
int main()
{
int a=300;
char *p=(char *)&a;
printf("%d\n",*p);
printf("%d",*++p);
return 0;
}
Output:
In LINUX GCC compiler
44
1
In TURBO C
44
1
(8) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
char c='A';
printf("%d %d",sizeof(c),sizeof('A'));
return 0;
}
Output:
In LINUX
1 4
In TURBO C
1 2
(9) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
enum color{RED,BLUE,GREEN=-2,YELLOW,PINK};
printf("%d %d",BLUE,PINK);
return 0;
}
Output:
In LINUX GCC compiler
1 0
In TURBO C
1 0
(10) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
-->
{
char c=127;
printf("%d",++c);
printf(" %d",++c);
return 0;
}
Output:
In LINUX GCC compiler
-128 -127
In TURBO C
-128 -127
Hints: char data type cyclic property.
(11) What will be output if you will execute following program by gcc compiler in Linux?#include"stdio.h"
struct info1{
char *title;
long int size;
double grade;
}hero1;
union info2
{
char *title;
long int size;
double grade;
}hero2;
int main()
{
printf("Size regarding structure: %d\n",sizeof(hero1));
printf("Size regarding union: %d",sizeof(hero2));
return 0;
}
Output:
In LINUX GCC compiler
Size regarding structure: 16
Size regarding union: 8
In TURBO C
Size regarding structure: 14
Size regarding union: 8
(12) What will be output if you will execute following program by gcc compiler in Linux?#define size(x) (char *)(x+1)-(char *)x
#include
int main()
{
long int *p;
long double *q;
printf("Size regarding long int: %d\n",size(p));
printf("Size regarding long double: %d",size(q));
return 0;
}
Output:
In LINUX GCC compiler
Size regarding long int: 4
Size regarding long double: 12
In TURBO C
Size regarding long int: 4
Size regarding long double: 10
(13) What will be output if you will execute following program by gcc compiler in Linux?#include
int main()
{
int i=2,j=5,k=3;
int a=i&&j>=k;
printf("%d",a);
return 0;
}
Output:
In LINUX GCC compiler
1
In TURBO C
1
Hints: Any conditional or relational operator returns 1 if condition is true otherwise it returns 0.
If you have any queries or suggestions in above c Linux interview questions, please share it.