C Language | 50 Minute‐Test 1


Instruction

  • Total number of questions : 50.
  • Time alloted : 50 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

What is the output of this C code?

   #include <stdio.h>

    void main()

    {

        double k = 0;

        for (k = 0.0; k < 3.0; k++);

            printf("%lf", k);

    }

 

A.
2.000000
B.
3.000000
C.
4.000000
D.
Run time error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

2.

What is the output of this C code?

  #include <stdio.h>

    int main()

    {

        int *p = NULL;

        for (foo(); p; p = 0)

            printf("In for loop\n");

            printf("After loop\n");

    }

 

A.
In for loop after loop
B.
Infinite loop
C.
In for loop after loop
D.
Depends on the value of NULL

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

3.

Where in C the order of precedence of operators do not exist?

A.
Within conditional statements, if, else
B.
Within while, do-while
C.
Within macro definition
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

4.

Which of the following operators has the lowest precedence?

A.
!=
B.
&&
C.
?:
D.
,

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

5.

What is the output of this C code?

  #include <stdio.h>

    int main()

    {

        int i = 5;

        i = i / 3;

        printf("%d\n", i);

        return 0;

    }

A.
Implementation defined
B.
1
C.
3
D.
Compile time error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

6.

What is the output of this C code?

  #include <stdio.h>

    int x = 5;

    void main()

    {

        int x = 3;

        m();

        printf("%d", x);

    }

    void m()

    {

        x = 8;

        n();

    }

    void n()

    {

        printf("%d", x);

    }

 

A.
8 3
B.
3 8
C.
8 5
D.
5 3

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

7.

What is the output of this C code?

 #include <stdio.h>

    void main()

    {

        unsigned int x = -5;

        printf("%d", x);

    }

 

A.
Run time error
B.
Aries
C.
-5
D.
5

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

8.

Which function definition will run correctly?

A.
int sum(int a, int b) return (a + b);
B.
int sum(int a, int b) {return (a + b);}
C.
int sum(a, b) return (a + b);
D.
Both (a) and (b)

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

9.

What is the output of this C code?

  #include <stdio.h>

    #define MIN 0

    #ifdef(MIN)

    #define MAX 10

    #endif

    int main()

    {

        printf("%d %d\n", MAX, MIN);

        return 0;

    }

 

A.
10 0
B.
Compile time error
C.
Both b and c
D.
Preprocessor error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

10.

What is the output of this C code?

  #include <stdio.h>

    void m();

    void n()

    {

        m();

    }

    void main()

    {

        void m()

        {

            printf("hi");

        }

    }

 

A.
hi
B.
Compile time error
C.
Nothing
D.
Varies

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

11.

What is the output of this C code?

 #include <stdio.h>

    void main()

    {

        int x = 1, y = 0, z = 5;

        int a = x && y || z++;

        printf("%d", z);

    }

 

A.
6
B.
5
C.
0
D.
Varies

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

12.

What is the final value of j in the below code?

 #include <stdio.h>

   int main()

   {

       int i = 0, j = 0;

       if (i && (j = i + 10))

           //do something

           ;

   }

 

A.
0
B.
10
C.
Depends on the compiler
D.
Depends on language standard

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

13.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int x = 1;

       int y =  x == 1 ? getchar(): 2;

       printf("%d\n", y);

   }

A.
Compile time error
B.
Whatever character getchar function returns
C.
Ascii value of character getchar function returns
D.
2

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

14.

Comment on the output of this C code?

  #include <stdio.h>

    void main()

    {

        int k = 8;

        int m = 7;

        int z = k < m ? k = m : m++;

        printf("%d", z);

    }

 

A.
Run time error
B.
7
C.
8
D.
Depends on compiler

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

15.

What is the output of this C code?

 #include <stdio.h>

   int main()

   {

       register static int i = 10;

       i = 11;

       printf("%d\n", i);

   }

 

A.
10
B.
Compile time error
C.
Undefined behaviour
D.
11

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

16.

Which among the following is wrong for “register int a;‿ ?

A.
Compiler generally ignores the request.
B.
You cannot take the address of this variable
C.
Access time to a is critical
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

17.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       register int x = 5;

       m();

       printf("x is %d", x);

   }

   void m()

   {

       x++;

   }

 

A.
6
B.
5
C.
Junk value
D.
Compile time error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

18.

What is the output of this C code(When 2 is entered)?

#include <stdio.h>

   void main()

   {

       int ch;

       printf("enter a value btw 1 to 2:");

       scanf("%d", &ch);

       switch (ch)

       {

       case 1:

           printf("1\n");

           break;

           printf("hi");

       default:

           printf("2\n");

       }

   }

 

A.
1
B.
2
C.
hi 2
D.
Run time error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

19.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int x = 97;

       switch (x)

       {

       case 'a':

           printf("yes ");

           break;

       case 97:

           printf("no\n");

           break;

       }

   }

 

A.
yes
B.
yes no
C.
Duplicate case value error
D.
Character case value error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

20.

Which keyword is used to come out of a loop only for that iteration?

A.
continue
B.
break
C.
return
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

21.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       int i = 0;

       int j = 0;

       for (i = 0;i < 5; i++)

       {

           for (j = 0;j < 4; j++)

           {

               if (i > 1)

                   continue;

                   printf("Hi \n");

           }

       }

   }

 

A.
Hi is printed 9 times
B.
Hi is printed 8 times
C.
Hi is printed 7 times
D.
Hi is printed 6 times

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

22.

Which of the following operators has an associativity from Right to Left?

A.
<=
B.
<<
C.
==
D.
+=

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

23.

Which of the following is the correct order of evaluation for the given expression? a = w % x / y * z;

A.
= % * /
B.
/ * % =
C.
% / * =
D.
* % / =

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

24.

Which function in the following expression will be called first? a = func3(6) – func2(4, 5) / func1(1, 2, 3);

A.
func1();
B.
func2();
C.
func3();
D.
Cannot be predicted.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

25.

Comment on the output of this C code?

#include <stdio.h>

   void main()

   {

       float x = 0.1;

       printf("%d, ", x);

       printf("%f", x);

   }

 

A.
0.100000, junk value
B.
Junk value, 0.100000
C.
0, 0.100000
D.
0, 0.999999

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

26.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int i = 23;

       char c = -23;

       if (i < c)

           printf("Yes\n");

       else

           printf("No\n");

   }

 

A.
No
B.
Yes
C.
Depends on the compiler
D.
Depends on the standard

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

27.

Which for loop has range of similar indexes of 'i' used in for (i = 0;i < n; i++)?

A.
for (i = n; i>0; i–)
B.
for (i = n; i >= 0; i–)
C.
for (i = n-1; i>0; i–)
D.
for (i = n-1; i>-1; i–)

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

28.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       double k = 0;

       for (k = 0.0; k < 3.0; k++)

           printf("Hello");

   }

 

A.
Run time error
B.
Hello is printed thrice
C.
Hello is printed twice
D.
Hello is printed infinitely

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

29.

What is the value of i and j in the below code?

#include <stdio.h>

   int x = 0;

   int main()

   {

       int i = (f() + g()) || g();

       int j = g() || (f() + g());

   }

   int f()

   {

       if (x == 0)

           return x + 1;

       else

           return x - 1;

   }

   int g()

   {

       return x++;

   }

 

A.
i value is 1 and j value is 1
B.
i value is 0 and j value is 0
C.
i and j value are undefined
D.
i value is 1 and j value is undefined

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

30.

The output of the code below is(when 1 is entered)

#include <stdio.h>

   void main()

   {

       double ch;

       printf("enter a value btw 1 to 2:");

       scanf("%lf", &ch);

       switch (ch)

       {

       case 1:

           printf("1");

           break;

       case 2:

           printf("2");

           break;

       }

   }

 

A.
Compile time error
B.
1
C.
2
D.
Varies

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

31.

What is the sequence for preprocessor to look for the file within <> ?

A.
The predefined location then the current directory
B.
The current directory then the predefined location
C.
The predefined location only
D.
The current directory location

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

<> first searches the predefined location for the specified file and then the current directory.

32.

What is the output of this C code?

#include <stdio.h>

   #define foo(m, n) m ## n

   void myfunc();

   int main()

   {

       myfunc();

   }

   void myfunc()

   {

       printf("%d\n", foo(2, 3));

   }

 

A.
Compile time error
B.
2 3
C.
23
D.
Undefined behaviour

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

33.

What is the output of this C code?

#include <stdio.h>

   int i;

   int main()

   {

       extern int i;

       if (i == 0)

           printf("scope rules\n");

   }

 

A.
Nothing as i value is not zero being automatic variable
B.
Compile time error due to multiple declaration
C.
Compile time error due to not defining type in statement extern i
D.
scope rules

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

34.

Comment on the output of this 2 C code?

#include <stdio.h> //Program 1

   int main()

   {

       int a;

       int b;

       int c;

   }

 

   #include <stdio.h> //Program 2

   int main()

   {

       int a;

       {

           int b;

       }

       {

           int c;

       }

   }

 

A.
They are both the same
B.
Scope of C is till the end of program
C.
All operation in Program 1 can also be performed in Program 2
D.
Both (a) and (c)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

35.

Which of the following operand can be applied to pointers p and q? (Assuming initialization as int *a = (int *)2; int *b = (int *)3;)

A.
a + b
B.
a – b
C.
a * b
D.
a / b

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

36.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       char *s = "hello";

       char *n = "cjn";

       char *p = s + n;

       printf("%c\t%c", *p, s[1]);

   }

 

A.
Compile time error
B.
h e
C.
c o
D.
h n

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

37.

#include are _______ files and #include “somefile.h‿ ________ files.

A.
Library, Library
B.
Library, user-created header
C.
User-created header, library
D.
They can include all types of file

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Both of these statement can be used to select any file.

38.

What is the output of this C code?

#include <stdio.h>

#define foo(m, n) m * n = 10

int main()

{

    printf("in main\n");

}

 

A.
In main
B.
Compilation error as lvalue is required for the expression m*n=10
C.
Preprocessor error as lvalue is required for the expression m*n=10
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Preprocessor just replaces whatever is given compiler then checks for error at the replaced part of the code. Here it is not replaced anywhere.

39.

What will be the output?

#include <stdio.h>

   double var = 8;

   int main()

   {

       int var = 5;

       printf("%d", var);

   }

 

A.
Compile time error due to wrong format identifier for double
B.
8
C.
5
D.
Compile time error due to redeclaration of variable with same name

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

40.

What is the output of this C code?

#include <stdio.h>

   #define foo(m, n) m ## n

   int main()

   {

       printf("%s\n", foo(k, l));

   }

 

A.
k l
B.
Compile time error
C.
kl
D.
Undefined behaviour

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

41.

What is the output of this C code?

#include <stdio.h>

   void f();

   int main()

   {

       #define max 10

       f();

       return 0;

   }

   void f()

   {

       printf("%d\n", max * 10);

   }

 

A.
100
B.
Compile time error since #define cannot be inside functions
C.
Compile time error since max is not visible in f()
D.
Undefined behaviour

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

42.

Automatic variables are allocated space in the form of a:

A.
random
B.
queue
C.
priority queue
D.
stack

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

43.

What linkage does automatic variables have?

A.
Internal linkage
B.
External linkage
C.
No linkage
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

44.

What is the output of this C code?

 

#include <stdio.h>

   void main()

   {

       int k = 5;

       int *p = &k;

       int **= &p;

       **m = 6;

       printf("%d\n", k);

   }

 

A.
5
B.
Compile time error
C.
6
D.
Junk

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

45.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       int a[3] = {1, 2, 3};

       int *p = a;

       int **r = &p;

       printf("%p %p", *r, a);

   }

 

A.
Different address is printed
B.
1 2
C.
1 1
D.
Same address is printed.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

46.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       char *a[10] = {"hi", "hello", "how"};

       int i = 0;

       for (i = 0;i < 10; i++)

       printf("%s", *(a[i]));

   }

 

A.
hi hello how followed by 7 null values
B.
Segmentation fault
C.
10 null values
D.
depends on compiler

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

47.

What is the output of this C code?

#include <stdio.h>

   void main()

   {

       int x = 4;

       int *p = &x;

       int *k = p++;

       int r = p - k;

       printf("%d", r);

   }

 

A.
4
B.
8
C.
1
D.
Run time error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

48.

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

A.
int
B.
float
C.
Depends on the data type of the parameter
D.
double

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

49.

The output of the code below is

#include <stdio.h>

   void main()

   {

       int k = m();

       printf("%d", k);

   }

   void m()

   {

       printf("hello");

   }

 

A.
hello 5
B.
Error
C.
Nothing
D.
Junk value

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

50.

What is the output of code given below if these two files are linked and run? in file test.c

#include <stdio.h>

   #include "test.h"

   int main()

   {

       i = 10;

       printf("%d ", i);

       foo();

   }

 

   in file test1.c

   #include <stdio.h>

   #include "test.h"

   int foo()

   {

       printf("%d\n", i);

   }

 

   in file test.h

   #include <stdio.h>

   #include <stdlib.h>

   static int i;

 

A.
1 0 0
B.
0 0
C.
10 10
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.


Feedback:

Submit your test now to view the Results and Statistics with answer explanation.