C/C /C Multiple Choice Questions C Functions Set 1 Sample Test,Sample questions

Question:
 Functions in C are ALWAYS:

1.Internal

2.External

3.Both Internal and External

4.External and Internal are not valid terms for functions


Question:
 The value obtained in the function is given back to main by using ________ keyword?

1.return

2.static

3.new

4.volatile


Question:
 What is the output of this C code?

    double i;
    int main()
    {
       printf("%g
",i);
       return 0;
    }

1.0

2.0.000000

3.Garbage value

4.Depends on the compiler


Question:
 What is the output of this C code?

    int x = 5;
    void main()
    {
        int x = 3;
        printf("%d", x);
        {
            int x = 4;
        }
        printf("%d", x);
    }

1. 3 3

2.3 4

3.3 5

4.Run time error


Question:
 What is the output of this C code?

void foo();
int main()
{
void foo(int);
foo(1);
return 0;
}
void foo(int i)
{
printf("2 ");
}

1.2

2.Compile time error

3.Depends on the compiler

4. Depends on the standard


Question:
 What is the problem in the following declarations?
     int func(int);
     double func(int);
     int func(float);

1.A function with same name cannot have different signatures

2.A function with same name cannot have different return types

3.A function with same name cannot have different number of parameters

4.All of the mentioned


Question:
 What is the return-type of the function sqrt()

1. int

2.float

3. double

4.Depends on the data type of the parameter


Question:
Automatic variables are allocated space in the form of a:

1.stack

2.queue

3.priority

4.random


Question:
Automatic variables are stored in:

1.stack

2.data segment

3.register

4.heap


Question:
Can variable i be accessed by functions in another source file?

    int i;
    int main()
    {
        printf("%d
", i);
    }

1.0

2.false

3.Only if static keyword is used

4.Depends on the type of the variable


Question:
Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ]

1.Yes, and we can use the function value conveniently

2.Yes, but we call the function again to get the value, not as convenient as in using variable

3.No, C does not support it

4.This case is compiler dependent


Question:
Default storage class if not any is specified for a local variable, is auto:

1.true

2.false

3.Depends on the standard

4.None of the mentioned


Question:
functions can return enumeration constants in c?

1.True

2.False

3.depends on the compiler

4.depends on the standard


Question:
functions can return structure in c?

1.True

2.False

3.Depends on the compiler

4. Depends on the standard


Question:
Property of external variable to be accessed by any source file is called by C90 standard as:

1.external linkage

2.external scope

3.global scope

4.global linkage


Question:
The output of the code below is

    int *m()
    {
        int *p = 5;
        return p;
    }
    void main()
    {
        int *k = m();
        printf("%d", k);
    }

1.1

2.Junk value

3.0

4.5


Question:
The output of the code below is

    int *m();
    void main()
    {
        int *k = m();
        printf("hello ");
        printf("%d", k[0]);
    }
    int *m()
    {
        int a[2] = {5, 8};
        return a;
    }

1.hello 5 8

2.hello 5

3. hello followed by garbage value

4.Compilation error


Question:
The output of the code below is

    int *m();
    void main()
    {
        int k = m();
        printf("%d", k);
    }
    int *m()
    {
        int a[2] = {5, 8};
        return a;
    }

1.5

2.8

3.Nothing

4.Varies


Question:
The output of the code below is

    void m(int k)
    {
        printf("hi");
    }
    void m(double k)
    {
        printf("hello");
    }
    void main()
    {
        m(3);
    }

1.hi

2. hello

3.hi

4.Nothing


Question:
The output of the code below is

    void main()
    {
        int k = m();
        printf("%d", k);
    }

    void m()
    {

        printf("hello");
    }

1.hello5

2.Error

3.Nothing

4. Junk value


Question:
The scope of an automatic variable is:

1.Within the block it appears

2.Within the blocks of the block it appears

3.Until the end of program

4.Both (a) and (b)


Question:
What is the default return type if it is not specified in function definition?

1.void

2. int

3.double

4.short int


Question:
What is the output of this C code?

    double foo();
    int main()
    {
        foo();
        return 0;
    }
    foo()
    {
        printf("2 ");
        return 2;
    }

1. 2

2.Compile time error

3.Depends on the compiler

4.Depends on the standard


Question:
What is the output of this C code?

    int *i;
    int main()
    {
        if (i == 0)
            printf("true
");
        return 0;
    }

1.true

2.true only if NULL value is 0

3.Compile time error

4.Nothing


Question:
What is the output of this C code?

    int *i;
    int main()
    {
        if (i == NULL)
            printf("true
");
        return 0;
    }

1.true

2.true only if NULL value is 0

3.Compile time error

4.Nothing


Question:
What is the output of this C code?

    int foo();
    int main()
    {
        int i = foo();
    }
    foo()
    {
        printf("2 ");
        return 2;
    }

1.1

2.Compile time error

3.Depends on the compiler

4.Depends on the standard


Question:
What is the output of this C code?

    int main()
    {
        auto i = 10;
        const auto int *p = &i;
        printf("%d
", i);
    }

1.10

2.Compile time error

3.Depends on the standard

4.Depends on the compiler


Question:
What is the output of this C code?

    int x;
    void main()
    {
        printf("%d", x);
    }

1.Junk value

2.Run time error

3.0

4.Undefined


Question:
What is the output of this C code?

    static int x = 5;
    void main()
    {
        x = 9;
        {
            int x = 4;
        }
        printf("%d", x);
    }

1.9

2.4

3.5

4.0


Question:
What is the output of this C code?

    static int x;
    void main()
    {
        int x;
        printf("x is %d", x);
 

1.0

2.Junk value

3.Run time error

4.Nothing


Question:
What is the output of this C code?

    void main()
    {
        m();
        m();
    }
    void m()
    {
        static int x = 5;
        x++;
        printf("%d", x);
    }

1.6 7

2.6 6

3.5 5

4.5 6


Question:
What is the output of this C code?

    void main()
    {
        m();
        printf("%d", x);
    }
    int x;
    void m()
    {
        x = 4;
    }

1.4

2.Compile time error

3.0

4.Undefined


Question:
What is the output of this C code?

    void main()
    {
        m();
        void m()
        {
            printf("hi");
        }
    }

1.hi

2.Compile time error

3.Nothing

4.Varies


Question:
What is the output of this C code?

    void main()
    {
        m();
    }
    void m()
    {
        printf("hi");
        m();
    }

1.Compile time error

2.hi

3.Infinite hi

4.Nothing


Question:
What is the output of this C code?

    void main()
    {
        static double x;
        int x;
        printf("x is %d", x);
    }

1.0

2.Nothing

3.Compile time error

4.Junk value


Question:
What is the output of this C code?

    void main()
    {
        static int x = 3;
        x++;
        if (x <= 5)
        {
            printf("hi");
            main();
        }
    }

1. Run time error

2.hi

3. infinite hi

4.hi hi


Question:
What is the output of this C code?

    void main()
    {
        static int x;
        if (x++ < 2)
        main();
    }

1.Infinite calls to main

2.Run time error

3.Varie

4.main is called twice


Question:
What is the output of this C code?

    void main()
    {
        static int x;
        printf("x is %d", x);
    }

1.0

2.1

3.Junk value

4.Run time error


Question:
What is the output of this C code?

   int x = 5;
    void main()
    {
        int x = 3;
        printf("%d", x);
        {
            x = 4;
        }
        printf("%d", x);
    }

1.Run time error

2.3

3.3 5

4.3 4


Question:
What is the output of this C code?

int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}

1.Compile time error as foo is local to main

2.1 2

3.2 1

4.Compile time error due to declaration of functions inside main


Question:
What is the output of this C code?

int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}

1.2 2

2.2

3.Compile time error

4. Depends on the compiler


Question:
What is the output of this C code?

void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}

1.Compile time error

2.2

3.Depends on the compiler

4.Depends on the standard


Question:
What is the output of this C code?

void m()
{
printf("hi");
}
void main()
{
m();
}

1.hi

2.Run time error

3.Nothing

4.Varies


Question:
What is the output of this C code?

void m()
{
printf("hi");
}
void main()
{
m();
}

1.hi

2.Run time error

3.Nothing

4.Varies


Question:
What is the output of this C code?

void m();
void n()
{
m();
}
void main()
{
void m()
{
printf("hi");
}
}

1.hi

2.Compile time error

3.Nothing

4.Varies


Question:
What is the output of this code having void return-type function?

     void foo()
    {
        return 1;
    }

    void main()
    {
        int x = 0;
        x = foo();
        printf("%d", x);
     }

1.1

2.2

3.Runtime error

4.Compile time error


Question:
What linkage does automatic variables have?

1.Internal linkage

2.External linkage

3.No linkage

4.None of the mentioned


Question:
What will be the data type returned for the following function?

    int func()
    {
        return (double)(char)5.0;
    }

1. char

2.int

3. double

4.multiple type-casting in return is illegal


Question:
What will be the output?

    double var = 8;
    int main()
    {
        int var = 5;
        printf("%d", var);
    }

1.5

2.8

3.Compile time error due to wrong format identifier for double

4.ompile time error due to redeclaration of variable with same name


Question:
What will be the output?

    int main()
    {
        printf("%d", d++);
    }
    int d = 10;

1.9

2.10

3.11

4.Compile time error


Question:
Which function definition will run correctly?

1.int sum(int a, int b) return (a + b);

2.int sum(int a, int b) {return (a + b);}

3.int sum(a, b) return (a + b);

4.Both (a) and (b)


Question:
Which of following is not accepted in C?

1.static a = 10; //static as

2.static int func (int); //parameter as static

3.static static int a; //a static variable prefixed with static

4.All of the mentioned


Question:
Which of the following are an external variable?

    int func (int a)
    {
        int b;
        return b;
    }
    int main()
    {
        int c;
        func (c);
    }
    int d;

1.a

2.b

3.c

4.d


Question:
Which of the following cannot be static in C?

1.Variables

2.Functions

3.Structures

4.None of the mentioned


Question:
Which of the following function declaration is illegal?

1.int 1bhk(int);

2.int 1bhk(int a);

3.int 2bhk(int*, int []);

4.All of the mentioned


Question:
Which of the following function declaration is illegal?

1.double func(); int main(){} double func(){}

2. double func(){}; int main(){}

3. int main() { double func(); } double func(){//statements}

4.None of the mentioned


Question:
Which of the following is a storage specifier?

1.enum

2.union

3.auto

4.volatile


Question:
Which part of the program address space is p stored in the code given below?

    int *p;
    int main()
    {
        int i = 0;
        p = &i;
        return 0;
    }

1.Code/text segment

2.Data segment

3.Bss segment

4.Stack


More MCQS

  1. C++ Programming MCQS Set-1
  2. C++ Multiple Choice Questions Set-1
  3. C++ Multiple Choice Questions Set-2
  4. C++ Programming MCQS Set-2
  5. C++ Programming MCQS Set-3
  6. C++ Programming MCQS Set-4
  7. C++ (CPP) MCQ Question with Answer
  8. Advanced c++ multiple choice question(MCQS)
  9. OOPS Quiz Questions and Answers(MCQS)
  10. C Programming - MCQ Questions Set 1
  11. C Programming - MCQ Questions Set 2
  12. C Programming - MCQ Questions Set 3
  13. C Programming - MCQ Questions Set 4
  14. C Programming - MCQ Questions Set 5
  15. C++ programming language MCQ Questions Set 1
  16. C++ programming language MCQ Questions Set 2
  17. C++ programming language MCQ Questions Set 3
  18. C++ programming language MCQ Questions Set 4
  19. C++ programming language MCQ Questions Set 5
  20. C++ Programming -Constructors and Destructors
  21. C++ Programming -OOPS Concepts
  22. C++ Programming - References
  23. C++ Programming - Functions
  24. C MCQS:-The ABC of C
  25. C MCQS Interview Questions
  26. C++ Questions and Answers – OOPs Basic Concepts
  27. C++ Questions and Answers – Returning Objects
  28. C Programming MCQ Part 1
  29. C Programming MCQ
  30. Computer Science & Engineering C Multiple Choice Questions set 1
  31. Computer Science & Engineering C Multiple Choice Questions set 2
  32. C Multiple Choice Questions C Functions Set 1
  33. C Multiple Choice Questions C Functions Set 2
  34. C Multiple Choice Questions C Operators
  35. C Multiple Choice Questions & AnswersConditional Expressions
  36. C Multiple Choice Questions & Answers Data Types
  37. C Multiple Choice Questions & Answers File Access
  38. Computer Science & Engineering Cloud Computing MCQs Part 1
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!