Fucntion Objectives

1. What is the output of this C code?

    #include <stdio.h>
    void main()
    {
        m();
        void m()
        {
            printf("hi");
        }
    }
a) hi
b) Compile time error
c) Nothing
d) Varies


Answer:b

2.What is the output of this C code?

    #include <stdio.h>
    void main()
    {
        int x = 3;
        x++;
        if (x <= 5)
        {
            printf("hi");
            main();
        }
else
{
break;
}
    }
a) Run time error
b) hi
c) Infinite hi
d) hi hi


Answer:d

3.What is the output of this C code?

#include <stdio.h>
    void m(int k)
    {
        printf("hi");
    }
    void m(double k)
    {
        printf("hello");
    }
    void main()
    {
        m(3);
    }
a) hi
b) hello
c) Compile time error
d) Nothing


Answer:c

4.The output of the code below is

    #include <stdio.h>
    int *m();
    void main()
    {
        int k = m();
        printf("%u", k);
    }
    int *m()
    {
        int a[2] = {5, 8};
        return a;
    }
a) 5
b) 8
c) address
d) nothing

Answer:c


5. What is the output of this C code?

    #include <stdio.h>
    int main()
    {
        int ary[4] = {1, 2, 3, 4};
        printf("%d\n", *ary);
    }
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable


Answer:a

8.What is the output of the code given below?

    #include <stdio.h>
    int main()
    {
        int ary[4] = {1, 2, 3, 4};
        int p[4];
        p = ary;
        printf("%d\n", p[1]);
    }
a) 1
b) Compile time error
c) Undefined behaviour
d) 2

Answer:b

9)findout output

int f(int a)
{
  a > 20? return(10): return(20);
}
int main()
{
    int f(int);
    int b;
    b = f(20);
    printf("%d\n", b);
    return 0;
}