Wednesday, February 20, 2013

C Snippet Output

What is the output of following code?
#include <stdio.h>
int main()
{
   printf("%d");
   return 0;
}
O/P: Garbage Value
***********************************************************************************
What is output of following code?
#include <stdio.h>
int main()
{
   int i=0;
   printf("%d,%d\n",i++,++i);
   return 0;
}
O/P: 1,2
*********************************************************************************** 
What is output of following code?
#include <stdio.h>
int main()
{
   int i=0;
   printf("%d,%d\n",i++,i++);
   return 0;
}
O/P: 1,0 
***********************************************************************************
What is output of following code? 
int main()
{
   int a = 5, b = 6, c;
   c = a+++b;
   printf("%d", c);
   return 0;
}
O/P: 11
***********************************************************************************
What is output of following code?
 int main()
{
   int key = 2;
    switch(key)
    {
        default :
            printf("In default\n");

        case 1:
            printf("In Case: 1\n");
    }
    return 0;
}
O/P:
In default
In Case: 1
***********************************************************************************
What is output of following code?
#include<stdio.h>
void main()
{
   char *strl="Indii";
   char *str2="ian";
   printf("%s\b\b%s",strl,str2);
}
O/P: Indian
***********************************************************************************
main()
{
  int a=2,b=3,c=4;
  printf(“%d%d%d”);
}

static int i=25;
Static int i;
main()
{
  Static int i;
  printf(“%d”,i);
}

struct bitone
{
  Int a:3;
  Int b:13;
  Int c:1;
}bit1;

main()
{
  printf(“%d”,sizeof(bit1));
}

main()
{
  char *str=NULL;
  strcpy(str,”an”);
  printf(“str);
}

main()
{
  arr[5]={1,2,3,4,5};
  printf(“%d”,-2[arr]);
}

main()
{
  char c=’\08’;
  printf(“%d”,c);
}

main()
{
  If(0.001-0.1f)
  {
    printf(“yes\n”);
  }
  else
  {
    printf(“No”);
  }
}

main()
{
  int a=2;
  a=˜a+2<<1;
  printf(“%d”,a);
}

No comments:

Post a Comment