Tuesday, April 10, 2012

Leap Year Problem.....

1-A year is called leap year if it is divisible by 400
2-If year is not divisible by 400 as well as 100 but it is divisible by 4 then that year are also leap year.

To determine a year is leap year or not...


#include<stdio.h>
int main(){
    int year;

    printf("Enter any year: ");
    scanf("%d",&year);

    if(((year%4==0)&&(year%100!=0))||(year%400==0))
         printf("%d is a leap year",year);
    else
         printf("%d is not a leap year",year);
 
    return 0;
}

To find leap year in between a range of year....



#include<stdio.h>
int main(){
    int year;
    int min_year,max_year;

    printf("Enter the lowest year: ");
    scanf("%d",&min_year);

    printf("Enter the heighest year: ");
    scanf("%d",&max_year);

    printf("Leap years in given range are: ");
    for(year = min_year;year <= max_year; year++){
         if(((year%4==0)&&(year%100!=0))||(year%400==0))
             printf("%d ",year);
    }
 
    return 0;
}

Reverse a number using c


1-Simple method  of reversing an integer number with the help of while loop....

#include<stdio.h>
int main(){
    int num,r,reverse=0;

    printf("Enter any number: ");
    scanf("%d",&num);

    while(num){
         r=num%10;
         reverse=reverse*10+r;
         num=num/10;
    }

    printf("Reversed of number: %d",reverse);
    return 0;
}

2-With help of for loop....

#include<stdio.h>
int main(){
    int num,r,reverse=0;

    printf("Enter any number: ");
    scanf("%d",&num);

    for(;num!=0;num=num/10){
         r=num%10;
         reverse=reverse*10+r;
    }

    printf("Reversed of number: %d",reverse);
    return 0;
}


3-With help of recursive function....
#include<stdio.h>
int main(){
    int num,reverse;

    printf("Enter any number: ");
    scanf("%d",&num);

    reverse=rev(num);
    printf("Reverse of number: %d",reverse);
    return 0;
}

int rev(int num){
    static sum,r;

    if(num){
         r=num%10;
         sum=sum*10+r;
         rev(num/10);
    }
    else
         return 0;

    return sum;
}

4-And finally method for reversing a very large number which is beyond the range of int and long int....

#include<stdio.h>
#define MAX 1000

int main(){

    char num[MAX];
    int i=0,j,flag=0;

    printf("Enter any positive integer: ");
    scanf("%s",num);

    while(num[i]){
         if(num[i] < 48 || num[i] > 57){
             printf("Invalid integer number");
             return 0;
         }
         i++;
    }

    printf("Reverse: ");
    for(j=i-1;j>=0;j--)
         if(flag==0 &&  num[j] ==48){
         }
         else{
             printf("%c",num[j]);
             flag =1;
         }

    return 0;


Wednesday, March 21, 2012

preprocessor


1) What will be output of following code?

#define max 10
void main()
{
    int i;
    i=++max;
    clrscr();
    printf("%d",i);
    getch();
}

output: compiler error.
Explanation:  max is preprocessor macro which process first before the actual compilation. Preprocessor paste the symbol to its constant value in entire the program before the compilation. so in this program max will be replaced by 10 before compilation. Thus program will be converted as:


void main()
{
     int i;
     i=++10;
     clrscr();
     printf("%d",i);
     getch();
}

To know how we can see intermediate file click here

In this program we are trying to increment a constant symbol.

Meaning of ++10 IS:-
10=10+1
or 10=11

Which is error because we cannot assign constant value to another constant value .Hence compiler will give error.



(2) What will be output of following code?

#define max 10+2
void main()
{
    int i;
    i=max*max;
    clrscr();
    printf("%d",i);
    getch();
}


Output:32

Explanation: 

max is preprocessor macro which process first before the actual compilation. Preprocessor paste the symbol to the its constant value without any calculation in entire the program before the compilation. So in this program max will be replaced by 10+2 before compilation. Thus program will be converted as:


void main()
{
    int i;
    i=10+2*10+2;
    clrscr();
    printf("%d",i);
    getch();
}

now i=10+2*10+2
i=10+20+2
i=32


(3) What will be output of following code?

#define A 4-2
#define B 3-1
void main()
{
     int ratio=A/B;
     printf("%d ",ratio);
     getch();
}


Output:3
Explanation: A and B preprocessor macro which process first before the actual compilation. Preprocessor paste the symbol to its constant value without any calculation in entire the program before the compilation. So in this program A and B will be replaced by 4-2 and 3-1 respectively before compilation. Thus program will be converted as:


void main()
{
    int ratio=4-2/3-1;
    printf("%d ",ratio);
    getch();
}


Here ratio=4-2/3-1
ratio=4-0-1
ratio=3


(4) What will be output of following code?

#define MAN(x,y) (x)>(y)?(x):(y)
void main()
{
       int i=10,j=9,k=0;
       k=MAN(i++,++j);
       printf("%d %d %d",i,j,k);
       getch();
}


Output: 11 11 11

Explanation: Preprocessor’s macro which process first before the actual compilation. Preprocessor paste the symbol to its constant value without any calculation in entire the program before the compilation. Thus program will be converted as:


void main()
{
    int i=10,j=9,k=0;
    k=(i++)>(++j)?(i++):(++j);
    printf("%d %d %d",i,j,k);
    getch();
}

now k=(i++)>(++j)?(i++):(++j);
first it will check the condition
(i++)>(++j)

i++ i.e. when postfix is used with variable in expression then expression is evaluated first with original value then variable is incremented

Or 10>10

This condition is false.
Now i = 10+1 = 11
There is rule, only false part will execute after? i.e. ++j, i++ will be not execute.
So after ++j
j=10+1=11;

And k will assign value of j .so k=11;


(5) What will be output of following code?

#define START main() {
#define PRINT printf("*******");
#define END }
START
PRINT
END


Output: *******
Explanation: 

Preprocessor macro which process first before the actual compilation. Preprocessor paste the symbol to its constant value i.e. symbols without any calculation in entire the program before the compilation. Thus program will be converted as:


main()
{
    printf("*******");
}


(6) What will be output of following code?
#define CUBE(x) (x*x*x)
#define M 5
#define N M+1
#define PRINT printf("RITESH");
void main()
{
      int volume =CUBE(3+2);
      clrscr();
      printf("%d %d ",volume,N);
      PRINT
      getch();
}


Output: 17 6
Explanation:

Preprocessor macro which process first before the actual compilation. Preprocessor paste the symbol to its constant value without any calculation in entire the program before the compilation. Thus program will be converted as:

void main()
{
    int volume =(3+2*3+2*3+2);
    clrscr();
    printf("%d %d ",volume,5+1);
    PRINT
    getch();
}




Wednesday, March 7, 2012

Technical set 2

1.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
switch(5/2*6+3.0){
case 3:printf("David Beckham");
break;
case 15:printf("Ronaldinho");
break;
case 0:printf("Lionel Messi");
break;
default:printf("Ronaldo");
}
}
Choose all that apply:

(A) David Beckham
(B) Ronaldinho
(C) Lionel Messi
(D) Ronaldo
(E) Compilation error

Explanation:e
2.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
unsigned char c=280;
switch(c){
printf("Start\t");
case 280:printf("David Beckham\t");
case 24: printf("Ronaldinho\t");
default: printf("Ronaldo\t");
printf("End");
}
}
Choose all that apply:

(A)Start David Beckham Ronaldinho Ronaldo End
(B) Start David Beckham Ronaldinho Ronaldo
(C) Start Ronaldinho Ronaldo End
(D)Ronaldinho Ronaldo End

(E) Compilation error
Explanation:d
3.
What will be output when you will execute following c code?
#include<stdio.h>
#define TRUE 1
void main(){
switch(TRUE){
printf("cquestionbank.blogspot.com");
}
}

Choose all that apply:
(A) cquestionbank.blogspot.com
(B) It will print nothing
(C) Runtime error
(D) Compilation error
(E) None of the above

Explanation:b
4.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
static int i;
int j=1;
int arr[5]={1,2,3,4};
switch(arr[j]){
case 1: i++;break;
case 2: i+=2;j=3;continue;
case 3: i%=2;j=4;continue;
default: --i;
}
printf("%d",i);
}

Choose all that apply:
(A) 0
(B) 1
(C) 2
(D) Compilation error
(E) None of the above

Explanation:d
5.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
static int i;
int j;
for(j=0;j<=5;j+=2)
switch(j){
case 1: i++;break;
case 2: i+=2;
case 4: i%=2;j=-1;continue;
default: --i;continue;
}
printf("%d",i);
}

Choose all that apply:
(A) 0
(B) 1
(C) 2
(D) Compilation error

(E) None of the above
Explanation:a
6.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=3;
while(1){
switch(x){
case 5/2: x+=x+++x;
case 3%4: x+=x---x;continue;
case 3>=3: x+=!!!x;break;
case 5&&0:x+=~~~x;continue;
default: x+=-x--;
}
break;
}
printf("%d",x);
}

Choose all that apply:
(A) 3
(B) -1
(C) 5
(D) Compilation error
(E) None of the above

Explanation:b
7.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
char *str="cquestionbank.blogspot.com";
int a=2;
switch('A'){
case 97:
switch(97){
default: str+=1;
}
case 65:
switch(97){
case 'A':str+=2;
case 'a':str+=4;
}
default:
for(;a;a--)
str+=8;
}
printf("%s",str);
}

Choose all that apply:
(A) cquestionbank.blogspot.com
(B) blogspot.com
(C) com
(D) Compilation error

(E) None of the above
Explanation:e
8.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
switch(2){
case 1L:printf("No");
case 2L:printf("%s","I");
goto Love;
case 3L:printf("Please");
case 4L:Love:printf("Hi");
}
}

Choose all that apply:
(A) I
(B) IPleaseHi
(C) IHi
(D) Compilation error
(E) None of the above

Explanation:c
9.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5;
a=a>=4;
switch(2){
case 0:int a=8;
case 1:int a=10;
case 2:++a;
case 3:printf("%d",a);
}
}
Choose all that apply:

(A) 8
(B) 11
(C) 10
(D) Compilation error
(E) None of the above

Explanation:e
10.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=3,b=2;
a=a==b==0;
switch(1){
a=a+10;
}
sizeof(a++);
printf("%d",a);
}

Choose all that apply:
(A) 10
(B) 11
(C) 12

(D)1
(E) Compilation error
Explanation:d

Technical set 1

1.
What will be output when you will execute following c code?#include<stdio.h>
void main(){
     int check=2;
     switch(check){
        case 1: printf("D.W.Steyn");
        case 2: printf(" M.G.Johnson");
        case 3: printf(" Mohammad Asif");
        default: printf(" M.Muralidaran");
     }
}
Choose all that apply:
(A)    M.G.Johnson   
(B)    M.Muralidaran   
(C)   
M.G.Johnson Mohammad Asif M.Muralidaran
(D)    Compilation error   
(E)    None of the above   
Explanation:c
2.
What will be output when you will execute following c code?#include<stdio.h>
void main(){
     int movie=1;
     switch(movie<<2+movie){
        default:printf("3 Idiots");
        case 4: printf(" Ghajini");
        case 5: printf(" Krrish");
        case 8: printf(" Race");
     }
}
Choose all that apply:
(A)    3 Idiots Ghajini Krrish Race   
(B)    Race   
(C)    Krrish   
(D)    Ghajini Krrish Race   
(E)    Compilation error   
Explanation:b
3.
What will be output when you will execute following c code?#include<stdio.h>
#define L 10
void main(){
     auto money=10;
     switch(money,money*2){
        case L:  printf("Willian");
                  break;
        case L*2:printf("Warren");
                  break;
        case L*3:printf("Carlos");
                  break;
        default: printf("Lawrence");
        case L*4:printf("Inqvar");
                  break;
     } 
}
Choose all that apply:
(A)    Willian   
(B)    Warren   
(C)    Lawrence Inqvar   
(D)    Compilation error: Misplaced default   
(E)    None of the above   
Explanation:b
4.
What will be output when you will execute following c code?#include<stdio.h>
void main(){
     int const X=0;
     switch(5/4/3){
        case X:  printf("Clinton");
                  break;
        case X+1:printf("Gandhi");
                  break;
        case X+2:printf("Gates");
                  break;
        default: printf("Brown");
     }
}
Choose all that apply:
(A)    Clinton   
(B)    Gandhi   
(C)    Gates   
(D)    Brown   
(E)    Compilation error   
Explanation:e
5.
What will be output when you will execute following c code?#include<stdio.h>
enum actor{
    SeanPenn=5,
    AlPacino=-2,
    GaryOldman,
    EdNorton
};
void main(){
     enum actor a=0;
     switch(a){
        case SeanPenn:  printf("Kevin Spacey");
                         break;
        case AlPacino:  printf("Paul Giamatti");
                         break;
        case GaryOldman:printf("Donald Shuterland");
                         break;
        case EdNorton:  printf("Johnny Depp");
     } 
}
Choose all that apply:
(A)    Kevin Spacey   
(B)    Paul Giamatti   
(C)    Donald Shuterland   
(D)    Johnny Depp   
(E)    Compilation error   
Explanation:d
6.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
     switch(*(1+"AB" "CD"+1)){
        case 'A':printf("Pulp Fiction");
                  break;
        case 'B':printf("12 Angry Man");
                  break;
        case 'C':printf("Casabance");
                  break;
        case 'D':printf("Blood Diamond");
     }
}
Choose all that apply:
(A)    Pulp Fiction   
(B)    12 Angry Man   
(C)    Casabance   
(D)    Blood Diamond   
(E)    Compilation error   
Explanation:c
7.
What will be output when you will execute following c code?#include<stdio.h>
void main(){
    char *str="ONE"
    str++;
    switch(str){
        case "ONE":printf("Brazil");
                break;
        case "NE": printf("Toy story");
                break;
        case "N":  printf("His Girl Friday");
                break;
        case "E":  printf("Casino Royale");
     } 
}
Choose all that apply:
(A)    Brazil   
(B)    Toy story   
(C)    His Girl Friday   
(D)    Casino Royale   
(E)    Compilation error   
Explanation:e
8.
What will be output when you will execute following c code?#include<stdio.h>
void main(){
    switch(5||2|1){
        case 3&2:printf("Anatomy of a Murder");
              break;
        case -~11:printf("Planet of Apes");
               break;
        case 6-3<<2:printf("The conversation");
               break;
    case 5>=5:printf("Shaun of the Dead");
     }
}
Choose all that apply:
(A)    Anatomy of a Murder   
(B)    Planet of Apes   
(C)    The conversation   
(D)    Shaun of the Dead   
(E)    Compilation error   
Explanation:e
9.
What will be output when you will execute following c code?#include<stdio.h>
void main(){
    switch(6){
        case 6.0f:printf("Sangakkara");
               break;
        case 6.0: printf("Sehwag");
               break;
        case 6.0L:printf("Steyn");
               break;
        default:  printf("Smith");
    }
}
Choose all that apply:
(A)    Sangakkara   
(B)    Sehwag   
(C)    Steyn   
(D)    Smith   
(E)    Compilation error   
Explanation:e
10.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    switch(0X0){
        case NULL:printf("Thierry Henry");
             break;
        case '\0':printf("Steven Gerrend");
             break;
        case 0: printf("Kaka");
             break;
        default: printf("Michael Ballack");
    }
}
Choose all that apply:
(A)    Thierry Henry   
(B)    Steven Gerrend   
(C)    Kaka   
(D)    Michael Ballack   
(E)    Compilation error   
Explanation:e

Sunday, March 4, 2012

C Placement Question

printf

(1)
#include<stdio.h>
#include<conio.h>
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<stdio.h>
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<stdio.h>
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<stdio.h>
#include<conio.h>
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<stdio.h>
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<stdio.h>
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<stdio.h>
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<stdio.h>
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<stdio.h>
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<stdio.h>
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<stdio.h>
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)

Thursday, March 1, 2012

if-else set 2

1.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=10;
if(printf("%d",a>=10)-10)
for(;;)
break;
else;
}
Choose all that apply:
(A) It will print nothing
(B) 0
(C) 1
(D) Compilation error: Misplaced else
(E) Infinite loop
Explanation:C
Return type of printf function is int. This function return a integral value which is equal to number of charcters printf function will print on console.
Operator >= will return 1 if both operands are either equal or first operand is grater than second operand. So a>=10 will return 1 since a is equal to 10.Thus printf function will print 1. Since this function is printing only one character so it will also return 1. So, printf("%d",a>=10) - 10
= 1 - 10
= -9
Since -9 is non-zero number so if(-9) is true condition and if clause will execute.
 
2.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5,b=10;
if(++a||++b)
printf("%d %d",a,b);
else
printf("John Terry");
}
Choose all that apply:
(A) 5 10
(B) 6 11
(C) 6 10
(D) 5 11
(E) John Terry
Explanation:c
Consider the following expression:
++a || ++b
In this expression || is Logical OR operator. Two important properties of this operator are:
Property 1:
(Expression1) || (Expression2)
|| operator returns 0 if and only if both expressions return a zero otherwise it || operator returns 1.
Property 2:
To optimize the execution time there is rule, Expression2 will only evaluate if and only if Expression1 return zero.
In this program initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b will not execute and if condition will be true and if clause will be executed.
 
3.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
static int i;
for(;;)
if(i+++"The Matrix")
printf("Memento");
else
break;
}
Choose all that apply:
(A) It will print Memento at one time
(B) It will print Memento at three times
(C) It will print Memento at 65535 times
(D) It will print Memento at infinite times
(E) Compilation error: Unknown operator +++
Explanation:C
think urself
 
4.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=1;
if(x--)
printf("The Godfather");
--x;
else
printf("%d",x);
}
Choose all that apply:
(A) The Godfather
(B) 1
(C) 0
(D) Compilation error
(E) None of the above
Explanation:d
If you are not using { and } in if clause then you can write only one statement. Otherwise it will cause of compilation error: Misplace else
 
5.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
if('\0');
else if(NULL)
printf("cquestionbank");
else;
}
Choose all that apply:
(A) cquestionbank
(B) It will print nothing
(C) Warning: Condition is always true
(D) Warning: Unreachable code
(E) Compilation error: if statement without any body
Explanation:b,d
‘\0’ is null character constant. Its ASCII value is zero. if(0) means false so program control will check it else if clause.
NULL is macro constant which has been defined in stdio.h which also returns zero.
 
6.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5,b=10;
clrscr();
if(a<++a||b<++b)
printf("%d %d",a,b);
else
printf("John Terry");
}
Choose all that apply:
(A) 5 10
(B) 6 11
(C) 6 10
(D) Compilation error
(E) John Terry
Explanation:e
Consider the following expression:
a<++a||b<++b
In the above expression || is logical OR operator. It divides any expression in the sub expressions. In this way we have two sub expressions:
(1) a<++a
(2) b<++b
In the expression: a< ++a
There are two operators. There precedence and associate are:
Precedence
Operator
Associate
1
++
Right to left
2
<
Left to right
From table it is clear first ++ operator will perform the operation then < operator.
One important property of pre-increment (++) operator is: In any expression first pre-increment increments the value of variable then it assigns same final value of the variable to all that variables. So in the expression: a < ++a
Initial value of variable a is 5.
Step 1: Increment the value of variable a in whole expression. Final value of a is 6.
Step 2: Now start assigning value to all a in the expression. After assigning 6 expression will be:
6 < 6
Since condition is false .So second expression i.e. b<++b will be evaluated. Again 11 < 11 is false. So || will operator will return zero and else clause will execute.
 
7.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=1,y=2;
if(--x && --y)
printf("x=%d y=%d",x,y);
else
printf("%d %d",x,y);
}
Choose all that apply:
(A) 1 2
(B) x=1 y=2
(C) 0 2
(D) x=0 y=1
(E) 0 1
Explanation:c
Consider the following expression:
--x && --y
In this expression && is Logical AND operator. Two important properties of this operator are:
Property 1:
(Expression1) && (Expression2)
&& operator returns 1 if and only if both expressions return a non-zero value other wise it && operator returns 0.
Property 2:
To optimize the execution time there is rule, Expression2 will only evaluate if and only if Expression1 return a non-zero value.
In this program initial value of x is 1. So –x will be zero. Since -–x is returning zero so -–y will not execute and if condition will be false. Hence else part will be executed.
 
8.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
signed int a=-1;
unsigned int b=-1u;
if(a==b)
printf("The Lord of the Rings");
else
printf("American Beauty");
}
Choose all that apply:
(A) The Lord of the Rings
(B) American Beauty
(C) Compilation error: Cannot compare signed number with unsigned number
(D) Compilation error: Undefined symbol -1u
(E) Warning: Illegal operation
Explanation:a
 
9.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
char c=256;
char *ptr="Leon";
if(c==0)
while(!c)
if(*ptr++)
printf("+%u",c);
else
break;
}
Choose all that apply:
(A) +256+256+256+256
(B)  0000
(C)  +0+0+0+0
(D)  It will print +256 at infinite times
(E)  Compilation error
Explanation:c
In the above program c is signed (default) char variable. Range of signed char variable in Turbo c is from -128 to 127. But we are assigning 256 which is beyond the range of variable c. Hence variable c will store corresponding cyclic value according to following diagram:
Since 256 is positive number move from zero in clock wise direction. You will get final value of c is zero.
if(c==0)
It is true since value of c is zero.
Negation operator i.e. ! is always return either zero or one according to following rule:
!0 = 1
!(Non-zero number) = 0
So,
!c = !0 =1
As we know in c zero represents false and any non-zero number represents true. So
while(!c) i.e. while(1) is always true.
In the above program prt is character pointer. It is pointing to first character of string “Leon” according to following diagram:
In the above figure value in circle represents ASCII value of corresponding character.
Initially *ptr means ‘L’. So *ptr will return ASCII value of character constant ‘L’ i.e. 76
if(*ptr++) is equivalent to : if(‘L’) is equivalent to: if(76) . It is true so in first iteration it will print +0. Due to ++ operation in second iteration ptr will point to character constant ‘e’ and so on. When ptr will point ‘\0’ i.e. null character .It will return its ASCII value i.e. 0. So if(0) is false. Hence else part will execute.
 
10.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=2;
if(a--,--a,a)
printf("The Dalai Lama");
else
printf("Jim Rogers");
}
Choose all that apply:
(A) The Dalai Lama
(B) Jim Rogers
(C) Run time error
(D) Compilation error: Multiple parameters in if statement
(E) None of the above
Explanation:b
Consider the following expression:
a-- , --a , a
In c comma is behaves as separator as well as operator.In the above expression comma is behaving as operator.Comma operator enjoy lest precedence in precedence table andits associatively is left to right. So first of all left most comma operator will perform operation then right most comma will operator in the above expression.
After performing a-- : a will be 2
After performing --a : a will be 0
a=0
As we know in c zero represents false and any non-zero number represents true. Hence else part will execute.

if-else set 1

(1).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    int a=5,b=10,c=1;
    if(a&&b>c){
         printf("cquestionbank");
    }
    else{
         break;
    }
}

Choose all that apply:

(A)  cquestionbank
(B)  It will print nothing
(C)  Run time error
(D)  Compilation error
(E)   None of the above

Explanation: D

Keyword break is not syntactical part of if-else statement. So we cannot use break keyword in if-else statement. This keyword can be use in case of loop or switch case statement.
Hence when you will compile above code compiler will show an error message: Misplaced break.

 

(2).

What will be output when you will execute following c code?

#define PRINT printf("Star Wars");printf(" Psycho");
#include<stdio.h>
void main(){
    int x=1;
    if(x--)
         PRINT
    else
         printf("The Shawshank Redemption");
}

Choose all that apply:

(A) Stars Wars Psycho
(B) The Shawshank Redemption
(C) Warning: Condition is always true
(D) Warning: Condition is always false
(E) Compilation error

Explanation:E

PRINT is macro constant. Macro PRINT will be replaced by its defined statement just before the actual compilation starts.  Above code is converted as:

void main(){
    int x=1;
    if(x--)
         printf("Star Wars");
printf(" Psycho");
    else
         printf("The Shawshank Redemption");
}
If you are not using opening and closing curly bracket in if clause, then you can write only one statement in the if clause. So compiler will think:
(i)
if(x--)
    printf("Star Wars");

It is if statement without any else. It is ok.
(ii)
printf(" Psycho");

It is a function call. It is also ok
(iii)
else
         printf("The Shawshank Redemption");

You cannot write else clause without any if clause. It is cause of compilation error. Hence compiler will show an error message: Misplaced else

 

(3).

What will be output when you will execute following c code?

#define True 5==5
#include<stdio.h>
void main(){
    if(.001-0.1f)
         printf("David Beckham");
    else if(True)
         printf("Ronaldinho");
    else
        printf("Cristiano Ronaldo");
}

Choose all that apply:

(A) David Beckham
(B) Ronaldinho
(C) Cristiano Ronaldo
(D) Warning: Condition is always true
(E) Warning: Unreachable code

Explanation:a,d,e

As we know in c zero represents false and any non-zero number represents true. So in the above code:

(0.001 – 0.1f) is not zero so it represents true. So only if clause will execute and it will print: David Beckham on console.
But it is bad programming practice to write constant as a condition in if clause. Hence compiler will show a warning message: Condition is always true

Since condition is always true, so else clause will never execute. Program control cannot reach at else part. So compiler will show another warning message:
Unreachable code

 

(4).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    int a=100;
    if(a>10)
         printf("M.S. Dhoni");
    else if(a>20)
         printf("M.E.K Hussey");
    else if(a>30)
           printf("A.B. de villiers");
}

Choose all that apply:

(A) M.S. Dhoni
(B) A.B. de villiers
(C) M.S Dhoni
      M.E.K Hussey
      A.B. de Villiers
(D) Compilation error: More than one conditions are true
(E) None of the above

Explanation:a

In case of if – if else – if else … Statement if first if clause is true the compiler will never check rest of the if else clause and so on.

 

(5).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    int x=-1,y=-1;
    if(++x=++y)
         printf("R.T. Ponting");
    else
         printf("C.H. Gayle");
}

Choose all that apply:

(A) R.T Ponting
(B) C.H. Gayle
(C) Warning: x and y are assigned a value that is never used
(D) Warning: Condition is always true
(E) Compilation error

Explanation:c,e

Consider following statement:
++x=++y
As we know ++ is pre increment operator in the above statement. This operator increments the value of any integral variable by one and return that value. After performing pre increments above statement will be:

0=0
In C language it is illegal to assign a constant value to another constant. Left side of = operator must be a container i.e. a variable. So compiler will show an error message: Lvalue required

In c if you assign any value to variable but you don’t perform any operator or perform operation only using unary operator on the variable the complier will show a warning message: Variable is assigned a value that is never 

 

(6).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    if(sizeof(void))
         printf("M. Muralilidaran");
    else
         printf("Harbhajan Singh");
}

Choose all that apply:

(A) M. Muralilidaran
(B) Harbhajan Singh
(C) Warning: Condition is always false
(D) Compilation error
(E) None of the above

Explanation:d

It illegal to find size of void data type using sizeof operator. Because size of void data type is meaning less.

 

(7).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    int m=5,n=10,q=20;
    if(q/n*m)
         printf("William Gates");
    else
         printf(" Warren Buffet");
         printf(" Carlos Slim Helu");
}

Choose all that apply:
(A) William Gates
(B)  Warren Buffet Carlos Slim Helu
(C) Run time error
(D) Compilation error
(E) None of the above

Explanation:e

Consider the following expression:
q / n * m

In this expression there are two operators. They are:
/: Division operator
*: Multiplication operator
Precedence and associate of each operator is as follow:

Precedence
Operator
Associate
1
/ , *
Left to right
Precedence of both operators is same. Hence associate will decide which operator will execute first. Since Associate is left to right. So / operator will execute then * operator will execute.
= q / n * m
= 20 / 10 * 5
= 2 * 5
=10

As we know in c zero represents false and any non-zero number represents true. Since 10 is non- zero number so if clause will execute and print: William Gates

Since in else clause there is not any opening and closing curly bracket. So compiler will treat only one statement as a else part. Hence last statement i.e.
printf(" Carlos Slim Helu");

is not part of if-else statement. So at the end compiler will also print: Carlos Slim Helu  
So output of above code will be:
William Gates Carlos Slim Helu

 

(8).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    if(!printf("Mukesh Ambani"))
    if(printf(" Lakashmi Mittal"))
}

Choose all that apply:

(A) Mukesh Ambani
(B)  Lakashmi Mittal
(C) It will print nothing
(D) Mukesh Ambani Lakashmi Mittal
(E) Compilation error: if statement without body

Explanation:a

Return type of printf function is int. This function return a integral value which is equal to number of characters a printf function will print on console. First of all printf function will: Mukesh Ambani. Since it is printing 13 character so it will return 13. So,

!printf("Mukesh Ambani")
= !13
= 0
In c language zero represents false. So if(0) is false so next statement which inside the body of first if statement will not execute.

 

(9).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    if("ABC") printf("Barack Obama\n");
    if(-1)    printf("Hu Jintao\n");
    if(.92L)  printf("Nicolas Sarkozy\n");
    if(0)     printf("Ben Bernanke\n");
    if('W')   printf("Vladimir Putin\n");
}

Choose all that apply:

(A) It will print nothing

(B) Barack Obama
       Hu Jintao
       Nicolas Sarkozy
       Vladimir Putin

(C) Barack Obama
       Hu Jintao
       Nicolas Sarkozy
       Ben Bernanke
       Vladimir Putin

(D)  Hu Jintao
       Nicolas Sarkozy
       Vladimir Putin

(E)  Compilation error

Explanation:b

“ABC”: It is string constant and it will always return a non-zero memory address.
0.92L: It is long double constant.
‘W’: It is character constant and its ASCII value is 

As we know in c language zero represents false and any non-zero number represents true. In this program condition of first, second, third and fifth if statements are true.

 

(10).

What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    if(0xA)
         if(052)
             if('\xeb')
                 if('\012')
                      printf("Tom hanks");
                 else;
             else;
         else;
    else;
}

Choose all that apply:

(A) Tom hanks
(B) Compilation error: Misplaced else
(C) Compilation error: If without any body
(D) Compilation error: Undefined symbol
(E) Warning: Condition is always true

Explanation:a,e

oxA: It is hexadecimal integer constant.
052: It octal integer constant.
‘\xeb’: It is hexadecimal character constant.
‘\012’: It is octal character constant.

As we know in c zero represents false and any non-zero number represents true. All of the above constants return a non-zero value. So all if conditions in the above program are true.

In c it is possible to write else clause without any body.

Friday, February 24, 2012

string

(1)

Without using any semicolon (;) in program write a c program which output is: HELLO WORLD?

Answer:
void main()
{
if(printf("HELLO WORLD"))
{
}
}

(2)

What will be output of following code?
void main()
{
char a[5];
a[0]='q';
a[1]='u';
a[2]='e';
clrscr();
printf("%s",a);
getch();
}
Output: garbage
Explanation: %s is used for string but a is not a string it is only array of character since its last character is not null character.
If you will write a[3]=’\0’; then output will be que.

(3)

Write a scanf statement which can store one line of string which includes white space.

Answer:
void main()
{
char a[30];
clrscr();
scanf("%[^\n]",a);
printf("%s",a);
getch();
}

(4)

Write a c program in which a scanf function can store a paragraph at time?

Answer:
void main()
{
char a[30];
clrscr();
scanf("%[^\t]",a);
printf("%s",a);
getch();
}
Note: Paragraph will end when you will press tab key.

(5)

In the following program
void main()
{
extern char a[30];
}
How much array a is reserving memory space?
Answer:
It is not reserving any memory space because array a has only declared it has not initialized .Any not initialized variable doesn’t reserve any memory space.

data types


1.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    printf("%d\t",sizeof(6.5));
    printf("%d\t",sizeof(90000));
    printf("%d",sizeof('A'));
}

Choose all that apply:
(A) 4 2 1
(B) 8 2 1
(C) 4 4 1
(D) 8 4 1
(E) 8 4 2

Explanation: D

2.
Consider on following declaring of enum.
(i)        enum  cricket {Gambhir,Smith,Sehwag}c;
(ii)      enum  cricket {Gambhir,Smith,Sehwag};
(iii)    enum   {Gambhir,Smith=-5,Sehwag}c;
(iv)      enum  c {Gambhir,Smith,Sehwag};
Choose correct one:
(A)Only (i) is correct declaration
(B) Only (i) and (ii) is correct declaration
(C) Only (i) and (iii) are correct declaration
(D) Only (i),(ii) and are correct declaration
(E) All four are correct declaration

Explanation: E

3.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    signed x;
    unsigned y;
    x = 10 +- 10u + 10u +- 10;
    y = x;
    if(x==y)
         printf("%d %d",x,y);
    else if(x!=y)
         printf("%u  %u",x,y);
}
Choose all that apply:
(A) 0 0
(B) 65536 -10
(C) 0 65536
(D) 65536 0
(E) Compilation error

Explanation:A

4.
Which of the following is not modifier of data type in c?

(A) extern
(B) interrupt
(C) huge
(D) register
(E) All of these are modifiers of data type

Explanation:E

5.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    double num=5.2;
    int  var=5;
    printf("%d\t",sizeof(!num));
    printf("%d\t",sizeof(var=15/2));
    printf("%d",var);
}

Choose all that apply:
(A) 4 2 7
(B) 4 4 5
(C) 2 2 5
(D) 2 4 7
(E) 8 2 7

Explanation: C

6.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    const int *p;
    int a=10;
    p=&a;
    printf("%d",*p);
}

Choose all that apply:
(A) 0
(B) 10
(C) Garbage value
(D) Any memory address
(E) Error: Cannot modify const object

Explanation: B

7.
Consider on following declaration:
(i)        short i=10;
(ii)      static i=10;
(iii)    unsigned i=10;
(iv)      const i=10;

Choose correct one:
(A)Only (iv) is incorrect
(B) Only (ii) and (iv) are incorrect
(C) Only (ii),(iii) and (iv) are correct
(D) Only (iii) is correct
(E) All are correct declaration

Explanation: E

8.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    int a= sizeof(signed) +sizeof(unsigned);
    int b=sizeof(const)+sizeof(volatile);
    printf("%d",a+++b);
}

Choose all that apply:
(A) 10
(B) 9
(C) 8
(D) Error: Cannot find size of modifiers
(E) Error: Undefined operator +++

Explanation: C

9.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    signed x,a;
    unsigned y,b;
    a=(signed)10u;
    b=(unsigned)-10;
    y = (signed)10u + (unsigned)-10;
    x = y;
    printf("%d  %u\t",a,b);
    if(x==y)
         printf("%d %d",x,y);
    else if(x!=y)
         printf("%u  %u",x,y);
}

Choose all that apply:
(A) 10 -10   0 0
(B) 10 -10   65516 -10
(C) 10 -10   10 -10
(D) 10 65526      0 0
(E) Compilation error

Explanation: D

10.
Which of the following is integral data type?

(A) void
(B) char
(C) float
(D) double
(E) None of these

Explanation: B

11.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    volatile int a=11;
    printf("%d",a);
}

Choose all that apply:
(A) 11
(B) Garbage
(C) -2
(D) We cannot predict
(E) Compilation error

Explanation: D

12.
What is the range of signed int data type in that compiler in which size of int is two byte?

(A) -255 to 255
(B) -32767 to 32767
(C) -32768 to 32768
(D) -32767 to 32768
(E) -32768 to 32767

Explanation: E

13.
What will be output when you will execute following c code?

#include<stdio.h>
const enum Alpha{
      X,
      Y=5,
      Z
}p=10;
void main(){
    enum Alpha a,b;
    a= X;
    b= Z;
 
    printf("%d",a+b-p);
 
}

Choose all that apply:
(A) -4
(B) -5
(C) 10
(D) 11
(E) Error: Cannot modify constant object

Explanation: A

14.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    char a=250;
    int expr;
    expr= a+ !a + ~a + ++a;
    printf("%d",expr);
}

Choose all that apply:
(A) 249
(B) 250
(C) 0
(D) -6
(E) Compilation error

Explanation: D

15.
Consider on order of modifiers in following declaration:

(i)char volatile register unsigned c;
(ii)volatile register unsigned char c;
(iii)register volatile unsigned char c;
(iv)unsigned char volatile register c;

Choose correct one:
(A) Only (ii) is correct declaration
(B) Only (i) is correction declaration
(C) All are incorrect
(D) All are correct but they are different
(E) All are correct and same

Explanation: E

16.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
    int a=-5;
    unsigned int b=-5u;
    if(a==b)
         printf("Avatar");
    else
         printf("Alien");
}

Choose all that apply:
(A) Avatar
(B) Alien
(C) Run time error
(D) Error: Illegal assignment
(E)   Error: Don’t compare signed no. with unsigned no.

Explanation: A

17.
What will be output when you will execute following c code?

#include<stdio.h>
extern enum cricket x;
void main(){
    printf("%d",x);
}
const enum cricket{
    Taylor,
    Kallis=17,
    Chanderpaul
}x=Taylor|Kallis&Chanderpaul;

Choose all that apply:
(A) 0
(B) 15
(C) 16
(D) 17
(E) Compilation error

Explanation: C

18.
Which of the following is not derived data type in c?

(A) Function
(B) Pointer
(C) Enumeration
(D) Array
(E) All are derived data type

Explanation: C

19.
What will be output when you will execute following c code?

#include<stdio.h>
enum A{
    x,y=5,
    enum B{
         p=10,q
    }varp;
}varx;

void main(){
    printf("%d %d",x,varp.q);
}

Choose all that apply:
(A) 0 11
(B) 5 10
(C) 4 11
(D)   0 10
(E) Compilation error

Explanation: E

20.
Consider on following declaration in c:

(i)short const register i=10;
(ii)static volatile const int i=10;
(iii)unsigned auto long register i=10;
(iv)signed extern float i=10.0;

Choose correct one:
(A) Only (iv)is correct
(B) Only (ii) and (iv) is correct
(C) Only (i) and (ii) is correct
(D) Only (iii) correct
(E) All are correct declaration

Explanation: C

Thursday, February 23, 2012

array


1.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    char arr[7]="Network";
    printf("%s",arr);
   }

(A) Network
(B) N
(C) network
(D) Garbage value
(E) Compilation error
Explanation: **d  ,array size overflow....
2.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    char arr[11]="The African Queen";
    printf("%s",arr);
}
(A) The African Queen
(B) The
(C) Queen
(D) null
(E) Compilation error
Explanation: **d
3.
What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    char arr[20]="MysticRiver";
    printf("%d",sizeof(arr));  
}
(A) 20
(B) 11
(C) 12
(D) 22
(E) 24
Explanation: **a

4.
What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    int const SIZE=5;
    int expr;
    double value[SIZE]={2.0,4.0,6.0,8.0,10.0};
    expr=1|2;
    printf("%f",value[expr]);
}
(A) 2.000000
(B) 4.000000
(C) 6.000000
(D) 8.000000
(E) Compilation error
Explanation: **d ,as precedence of bitwise inclusive OR ( | ) is more than  assignment operator so                               1|2=3  expr=3;

5.
What will be output if you will execute following c code?

#include<stdio.h>
enum power{
    Dalai,
    Vladimir=3,
    Barack,
    Hillary
};
void main(){
    float leader[Dalai+Hillary]={1.f,2.f,3.f,4.f,5.f};
    enum power p=Barack;
    printf("%0.f",leader[p>>1+1]);
}
(A) 1
(B) 2
(C) 3
(D) 5
(E) Compilation error
Explanation: **b  , initial value of p is 4 right shift by 2 make p=1 leader[1]=2

6.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    char *cricket[var+~0]={"clarke","kallis"};
    char *ptr=cricket[1+~0];
    printf("%c",*++ptr);
}
(A) k
(B) a
(C) l
(D) i
(E) Compilation error
Explanation: **c

7.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11};
    printf("%o",data[0][2][1]);
}
(A) 5
(B) 6
(C) 7
(D) 8
(E) Compilation error
Explanation: **a

8.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    short num[3][2]={3,6,9,12,15,18};
    printf("%d   %d",*(num+1)[1],**(num+2));
}
(A) 12  15
(B) 12  12
(C) 15  15
(D) 15  12
(E) Compilation error
Explanation: **c

9.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    char *ptr="cquestionbank";
    printf("%d",-3[ptr]);
}
(A) 100
(B) -100
(C) 101
(D) -101
(E) Compilation error
Explanation: **d

10.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    long  myarr[2][4]={0l,1l,2l,3l,4l,5l,6l,7l};
    printf("%ld\t",myarr[1][2]);
    printf("%ld%ld\t",*(myarr[1]+3),3[myarr[1]]);
    printf("%ld%ld%ld\t" ,*(*(myarr+1)+2),*(1[myarr]+2),3[1[myarr]]);
   }
(A) 6   66   777
(B) 6   77   667
(C) 5   66   777
(D) 7   77   666
(E) 6   67   667
Explanation: **b

11.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int array[2][3]={5,10,15,20,25,30};
    int (*ptr)[2][3]=&array;
    printf("%d\t",***ptr);
    printf("%d\t",***(ptr+1));
    printf("%d\t",**(*ptr+1));
    printf("%d\t",*(*(*ptr+1)+2));
}
(A) 5   Garbage value   20   30
(B)   5    15    20    25
(C)  10   20    30    30
(D) 5    15    20    30
(E)  Compilation error

Explanation: **a


12.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    static int a=2,b=4,c=8;
    static int *arr1[2]={&a,&b};
    static int *arr2[2]={&b,&c};
    int* (*arr[2])[2]={&arr1,&arr2};
    printf("%d %d\t",*(*arr[0])[1],  *(*(**(arr+1)+1)));
}
(A) 2  4
(B) 4  2
(C) 4  8
(D) 8  4
(E) 8  2
Explanation: **c


13.
What will be output if you will execute following c code?

#include<stdio.h>
#include<math.h>
double myfun(double);
void main(){
    double(*array[3])(double);
    array[0]=exp;
    array[1]=sqrt;
    array[2]=myfun;
    printf("%.1f\t",(*array)((*array[2])((**(array+1))(4))));
}
double myfun(double d){
       d-=1;
       return d;
}
(A) 1.4
(B) 2.8
(C) 4.2
(D) 3.0
(E) 2.7
Explanation: **e


14.
What will be output if you will execute following c code?

#include<stdio.h>
#include<math.h>
typedef struct{
    char *name;
    double salary;
}job;
void main(){
    static job a={"TCS",15000.0};
    static job b={"IBM",25000.0};
    static job c={"Google",35000.0};
    int x=5;
    job * arr[3]={&a,&b,&c};
    printf("%s  %f\t",(3,x>>5-4)[*arr]);
}
double myfun(double d){
       d-=1;
       return d;
}
(A) Google 35000.000000
(B) TCS  15000.000000
(C) IBM  25000.000000
(D) null   15000.000000
(E) Google   null
Explanation: **a


15.
What will be output if you will execute following c code?

#include<stdio.h>
union group{
    char xarr[2][2];
    char yarr[4];
};
void main(){
    union group x={'A','B','C','D'};
    printf("%c",x.xarr[x.yarr[2]-67][x.yarr[3]-67]);
}
(A) A
(B) B
(C) C
(D) D
(E) null
Explanation: **b


16.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int a=5,b=10,c=15;
    int *arr[3]={&a,&b,&c};
    printf("%d",*arr[*arr[1]-8]);
}
(A) 5
(B) 10
(C) 18
(D) Garbage value
(E)   Compilation error

Explanation: **e


17.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int arr[][3]={{1,2},{3,4,5},{5}};
    printf("%d %d %d",sizeof(arr),arr[0][2],arr[1][2]);
}
(A)   6  0 4
(B) 6  1 5
(C) 18 0 5
(D) 18 1 5
(E) Compilation error
Explanation: **c


18.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int xxx[10]={5};
    printf("%d %d",xxx[1],xxx[9]);
}
(A) 0  5
(B) 5  5
(C) 5  0
(D) 0  0
(E) Compilation error
Explanation: **d
19.
What will be output if you will execute following c code?

#include<stdio.h>
#define WWW -1
enum {cat,rat};
void main(){
    int Dhoni[]={2,'b',0x3,01001,'\x1d','\111',rat,WWW};
    int i;
    for(i=0;i<8;i++)
         printf(" %d",Dhoni[i]);
}
(A) 2 98 3 513 29 73 0 -1
(B) 2 98 3 513 30 73 1 -1
(C) 2 99 3 513 29 73 1 -1
(D) 2 98 3 513 29 73 1 -1
(E) Compilation error
Explanation: **d

20.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    long double a;
    signed char b;
    int arr[sizeof(!a+b)];
    printf("%d",sizeof(arr))
}
(A) 8
(B) 9
(C) 1
(D) 4
(E) Compilation error
Explanation: **d