Showing posts with label technical question in c language. Show all posts
Showing posts with label technical question in c language. Show all posts

Wednesday, September 17, 2008

Placement Interview Question with answer in c Programming language


                                  
1.void main()
 {
  int d=5;
  printf("%f",d);
 }
output?

Ans: Undefined
Explanation:-
floating point formats not linked 

2.
void main()
{
  int i;
  for(i=1;i<4;i++)
  {
  switch(i)
  {
 case 1:

  printf("%d",i);
  break;

 case 2:
  printf("%d",i);
  break;
 case 3:
  printf("%d",i);
  break;
}
 switch(i) 
case 4:
printf("%d",i);

}
}

output:

Ans: 1,2,3

3.
void main()
  {
 char *s="\12345s\n";
 printf("%d",sizeof(s));
 }

output:-
2

4.
void main()
  {
 char *s="\12345s\n";
 printf("%d",sizeof(*s));
 }
output:-
1

5.
void main()
{
  unsigned i=1; /* unsigned char k= -1 => k=255; */
  signed j=-1; /* char k= -1 => k=65535 */
      /* unsigned or signed int k= -1 =>k=65535 */
 if(i
   printf("less");
 else if(i>j)
  printf("greater");
else if(i==j)
  printf("equal");
}


output:-less

Placement Technical C programming Question with answer

1.
int b=10;
  int *p=&b;
  *p++;
  printf("%d",*p);

what is the output?

output:- Garbage value 

2.
 int b=10;
  int *p=&b;
  ++*p;
  printf("%d",*p);

what is the output?

output:- 11

3. main()
{
char *a="hello";
char *b="bye";
char *c="hai";
int x=10,y=100;
c=(x
printf("%s",c);
}
whats the output?

output:-hello

4. main()
{
char *a="hello";
char *b="bye";
char *c="hai";
int x=10,y=100;
c=(x>y)?a:b;
printf("%s",c);
}
whats the output?

output:-
bye

5.
void main()
 {
  int a,b;
  a=sumdig(123);
  b=sumdig(123);
  printf("%d %d",a,b);
  getch();
 }
 int sumdig(int n)
  {
  static int sum;
  int d;
  if(n!=0)
  {
   d=n%10;
   n=(n-d)/10;
   sum=sum+d;
   sumdig(n);
  }

    return sum;
  }
whats the output?

output:-
6  12

My Blog List