Monday, March 10, 2008

C++ C Interview Question Papers

36)
What is the output of the following program?
#include<stdio.h>
int fun1()
{
static int c=20;
return --c;
}

int fun2()
{
static int c=1;
return fun1()+c--;
}

int main()
{
int i=0;
while(i<fun2())
printf("%d ",i++);
return 0;
}
Ans:



37)
What is the output of the following program?
#include<stdio.h>
#include<string.h>
void p(char *a)
{
static int y=1;
if(y=1-y) printf("%c",*a);
return;
}

int main()
{
char *a;a=(char*)malloc(20*sizeof(char));
strcpy(a,"DbugtheCbug");
while(*a!='\0') p(a++);
printf("\n");
return 0;
}
Ans:



38)
Give the output of the following piece of code.
#include <stdio.h>
main()
{
int a=4,b=10;


printf("%d %d %d %d\n",a,a^=b=b^=a=a^=b,b,printf("%d %d %d\n",b,a,a^=b=b^=a=a^=b));


}
Ans:




39)
Predict the output of the following program.
#include<stdio.h>
int main()
{
int x = 5,p = 10;
printf("%*d",x,p);
}
Ans:




40)
What is the output of the following code?
#include<stdio.h>
int main()
{
int i=2;
i=i++;
printf("%d ",i++ + i++);
}
Ans:




41)
Predict the output for the below code.
#include<stdio.h>
int main()
{
int a[]={2,3,4,5,6};
int i=0;
printf("%d",a[i++]+i[a+1]);
return(0);
}
Ans:



42)
What is the output of the following piece of code?
#include<stdio.h>
#include<stdlib.h>
void weird(int *a)
{
a=(int*)malloc(sizeof(int));
}
int main()
{
int *a;
weird(a);
*a=6;
printf("%d\n",*a);
return(0);
}
Ans:



43)
What is the output of the following piece of code?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",*ptr++);
return(0);
}
Ans:




44)
Correct the following code in case of any errors.
#include <stdlib.h>
#include <stdio.h>
#define SIZE 15
int main()
{
int *a, i;
a = (void*)malloc(SIZE*sizeof(int));
for (i=0; i<SIZE; i++)
*(a + i) = (int)i * i;
for (i=0; i<SIZE; i++)
printf("%d\n", *a++);
free(a);
return 0;
}
Ans:




45)
What is the output of the following program?
#include<stdio.h>
int main()
{
char c;
c=255;
printf("%d",c);
return(0);
}