Showing posts with label C Language. Show all posts
Showing posts with label C Language. Show all posts

Tuesday, June 12, 2012

C Linux Interview Questions and Answers

C Linux interview questions and answers

C Linux interview questions and 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 to 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 of near, far and 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 of any type of pointer in Linux is 4 and 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 of short int: %d\n",sizeof(a));
    printf("Size of int: %d\n",sizeof(b));
    printf("Size of long int: %d\n",sizeof(c));
    printf("Size of float: %d\n",sizeof(d));
    printf("Size of double: %d\n",sizeof(e));
    printf("Size of long double: %d\n",sizeof(f));
    printf("Size of char: %d\n",sizeof(g));
        return 0;
}

Output:
In LINUX GCC compiler
Size of short int: 2
Size of int: 4
Size of long int: 4
Size of float: 4
Size of double: 8
Size of long double: 12
Size of char: 1
In TURBO C
Size of short int: 2
Size of int: 2
Size of long int: 4
Size of float: 4
Size of double: 8
Size of long double: 10
Size of 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 of structure: %d\n",sizeof(hero1));
    printf("Size of union:  %d",sizeof(hero2));
    return 0;
}

Output:
In LINUX GCC compiler
Size of structure: 16
Size of union:  8
In TURBO C
Size of structure: 14
Size of 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 of long int: %d\n",size(p));
    printf("Size of long double: %d",size(q));
        return 0;
}

Output:
In LINUX GCC compiler
Size of long int: 4
Size of long double: 12
In TURBO C
Size of long int: 4
Size of 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.

Example of recursion in C programming

Example of recursion in C programming

Collections of c recursion programs examples frequently asked in interview 

  1. Sum of n numbers using recursion in c
  2. Matrix multiplication using recursion in c
  3. Multiplication using recursion in c
  4. Lcm using recursion in c
  5. Using recursion in c find the largest element in an array
  6. Prime number program in c using recursion
  7. Decimal to binary conversion in c using recursion
  8. C program for fibonacci series using recursion
  9. Reverse a string using recursion
  10. Write a program for palindrome using recursion
  11. Find factorial of a number using recursion in c program
  12. Find gcd of a number using recursion in c program
  13. Find sum of digits of a number using recursion using cprogram
  14. Find power of a number using recursion using c program
  15. Binary search through recurssion using c programReverse a number using recursion in c program

Printf function Questions and Answer with Solution

Printf function questions and answer with solution 

 

Printf objective types interview questions and answers  


(1)
#include
#include
void main()
{
int a=5,b=6,c=11;
clrscr();
printf("%d %d %d");
getch();
}
What will output when you compile and run the above code?
(a)Garbage value garbage value garbage value
(b)5 6 11
(c)11 6 5
(d)Compiler error
Answer: (c)
(2)
#include
void main()
{
char *str="CQUESTIONBANK";
clrscr();
printf(str+9);
getch();
}
What will output when you compile and run the above code?
(a)CQESTIONBANK
(b)CQUESTION
(c)BANK
(d)Compiler error
Answer: (c)
(3)
#include
void main()
{
clrscr();
printf("%d",printf("CQUESTIONBANK"));
getch();
}
What will output when you compile and run the above code?
(a)13CQUESTIONBANK
(b)CQUESTIONBANK13
(c)Garbage CQUESTIONBANK
(d)Compiler error
Answer: (b)
(4)
#include
#include
void main()
{
short int a=5;
clrscr();
printf("%d"+1,a);
getch();
}
What will output when you compile and run the above code?
(a)6
(b)51
(c)d
(d)Compiler error
Answer: (c)
(5)
#include
void main()
{
int i=85;
clrscr();
printf("%p %Fp",i,i);
getch();
}
What will output when you compile and run the above code?
(a)85 85
(b)0055 034E:0055
(c)0055 FFFF:0055
(d)Compiler error
Answer: (b)
 (6)
#include
static struct student
{
int a;
    int b;
    int c;
int d;
}s1={6,7,8,9},s2={4,3,2,1},s3;
void main()
{
s3=s1+s2;
clrscr();
printf("%d %d %d %d",s3.a,s3.b,s3.c,s3.d);
getch();
}
What will output when you compile and run the above code?
(a)6789
(b)4321
(c)10101010
(d)Compiler error
Answer: (d)
(7)
#include
extern struct student
{
int a;
    int b;
    int c;
int d;
}s={6,7,8,9};
void main()
{
clrscr();
printf("%d %d %d %d",s.a,s.b,s.c,s.d);
getch();
}
What will output when you compile and run the above code?
(a)6789
(b)9876
(c)0000
(d)Compiler error
Answer: (a)
(8)
#include
struct student
{
static int a;
register int b;
auto int c;
extern int d;
}s={6,7,8,9};
void main()
{
printf("%d %d % %d",s.a,s.b,s.c,s.d);
}
What will output when you compile and run the above code?
(a)6789
(b)9876
(c)0000
(d)Compiler error
Answer: (d)
(9)
#include
struct student
{
int roll;
int cgpa;
int sgpa[8];
};
void main()
{
struct student s={12,8,7,2,5,9};
int *ptr;
ptr=(int *)&s;
clrscr();
printf("%d",*(ptr+3));
getch();
}
What will output when you compile and run the above code?
(a)8
(b)7
(c)2
(d)Compiler error
Answer: (c)
(10)
#include
struct game
{
int level;
int score;
struct player
{
char *name;
}g2={"anil"};
}g3={10,200};
void main()
{
struct game g1=g3;
clrscr();
printf("%d  %d  %s",g1.level,g1.score,g1.g2.name);
getch();
}
What will output when you compile and run the above code?
(a)10 200 anil
(b)200 10 anil
(c)10 200 null
(d)Compiler error
Answer: (d)
(11)
#include
struct game
{
int level;
int score;
struct player
{
char *name;
}g2;
}g1;
void main()
{
clrscr();
printf("%d  %d  %s",g1.level,g1.score,g1.g2.name);
getch();
}
What will output when you compile and run the above code?
(a)Garbage_value garbage_value garbage_value
(b)0 0 (null)
(c)Run time error
(d)Compiler error
Answer: (b)