Saturday, March 17, 2012

What is the output ?

1. what is the output of the following program ? “alloc failed or alloc successful” ?

#include<stdio.h>
void alloc(int *p)
{
p=(int*)malloc(10*sizeof(*p));

}
main()
{
int *p=NULL;
alloc(p);
if(NULL==p)
printf("alloc failed");
else
printf("alloc successful");
}
Ans: alloc failed

make changes to get “alloc successful” as output.

2. what is the output of the program ?

#include<stdio.h>
main()
{
    struct node
    {
            int a;
            int b;
            int c;
    };
    struct node s={3,5,6};
    struct node *pt=&s;
    printf("%d",*(int*)pt);
    }
Ans: 3

3.  what is the output of the following program ?

#include<stdio.h>
main()
{
    printf(3+"Hello World");
    }
Ans: lo World

4. what is the output of the following program ?

#include<stdio.h>
main()
{
    int a=0;
    if(a=2)
    printf("I am inside IF\n");
    printf("It is correct");
    }
Ans:

I am inside IF
It is correct

5. what is the output ?

#include<stdio.h>
main()
{
    unsigned i=5;
    if(i > -5)
        printf("it is less than -5");
}
Ans: No output

No comments:

Post a Comment