Thursday, July 31, 2014

C Programming

1. 
What will be the output of the program?
#include<stdio.h>
int fun(int(*)());

int main()
{
    fun(main);
    printf("Hi\n");
    return 0;
}
int fun(int (*p)())
{
    printf("Hello ");
    return 0;
}
A.Infinite loopB.Hi
C.Hello HiD.Error
2. 
What will be the output of the program?
#include<stdio.h>

int fun(int i)
{
    i++;
    return i;
}

int main()
{
    int fun(int);
    int i=3;
    fun(i=fun(fun(i)));
    printf("%d\n", i);
    return 0;
}
A.5B.4
C.ErrorD.Garbage value
3. 
What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
    float k=3;
    fun(k=fun(fun(k)));
    printf("%f\n", k);
    return 0;
}
int fun(int i)
{
    i++;
    return i;
}
A.5.000000B.3.000000
C.Garbage valueD.4.000000

4. 
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i=0;
    i++;
    if(i<=5)
    {
        printf("IndiaBIX");
        exit(1);
        main();
    }
    return 0;
}
A.Prints "IndiaBIX" 5 times
B.Function main() doesn't calls itself
C.Infinite loop
D.Prints "IndiaBIx"
5. 
Which of the following statements are correct about the program?
#include<stdio.h>

int main()
{
    printf("%p\n", main());
    return 0;
}
A.It prints garbage values infinitely
B.Runs infinitely without printing anything
C.Error: main() cannot be called inside printf()
D.No Error and print nothing

No comments: