Online C Programming Test - C Programming Test - Random



Loading...  Loading Test...

Instruction:

  • Total number of questions : 20.
  • Time alloted : 30 minutes.
  • Each question carry 1 mark, no negative marks.
  • DO NOT refresh the page.
  • All the best :-).

1.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    printf("%c\n", ~('C'*-1));
    return 0;
}

A.
A
B.
B
C.
C
D.
D

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

2.

What will be the output of the program?

#include<stdio.h>
#include<math.h>

int main()
{
    float i = 2.5;
    printf("%f, %d", floor(i), ceil(i));
    return 0;
}

A.
2, 3
B.
2.000000, 3
C.
2.000000, 0
D.
2, 0

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Both ceil() and floor() return the integer found as a double.

floor(2.5) returns the largest integral value(round down) that is not greater than 2.5. So output is 2.000000.

ceil(2.5) returns 3, while converting the double to int it returns '0'.
So, the output is '2.000000, 0'.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

3.

Which of the following statements are FALSE about the below code?

int main(int ac, char *av[])
{
}

A.
ac contains count of arguments supplied at command-line
B.
av[] contains addresses of arguments supplied at a command line
C.
In place of ac and av, argc and argv should be used.
D.
The variables ac and av are always local to main()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
int main()
{
    char *str1="India";
    char *str2="BIX";
    JOIN(str1, str2);
    return 0;
}

A.
str1=IndiaBIX str2=BIX
B.
str1=India str2=BIX
C.
str1=India str2=IndiaBIX
D.
Error: in macro substitution

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

5.

What will be the output of the program?

#include<stdio.h>
#define CUBE(x) (x*x*x)

int main()
{
    int a, b=3;
    a = CUBE(b++);
    printf("%d, %d\n", a, b);
    return 0;
}

A.
9, 4
B.
27, 4
C.
27, 6
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The macro function CUBE(x) (x*x*x) calculates the cubic value of given number(Eg: 103.)

Step 1: int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.

Step 2: a = CUBE(b++); becomes

=> a = b++ * b++ * b++;

=> a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not incremented in this statement.

=> a = 27; Here, 27 is store in the variable a. By the way, the value of variable b is incremented by 3. (ie: b=6)

Step 3: printf("%d, %d\n", a, b); It prints the value of variable a and b.

Hence the output of the program is 27, 6.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

6.

What will be the output of the program?

#include<stdio.h>
#define MAX(a, b) (a > b ? a : b)

int main()
{
    int x;
    x = MAX(3+2, 2+7);
    printf("%d\n", x);
    return 0;
}

A.
8
B.
9
C.
6
D.
5

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.

Step 1 : int x; The variable x is declared as an integer type.

Step 2 : x = MAX(3+2, 2+7); becomes,

=> x = (3+2 > 2+7 ? 3+2 : 2+7)

=> x = (5 > 9 ? 5 : 9)

=> x = 9

Step 3 : printf("%d\n", x); It prints the value of variable x.

Hence the output of the program is 9.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

7.

In the following code what is 'P'?

typedef char *charp;
const charp P;

A.
P is a constant
B.
P is a character constant
C.
P is character type
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

8.

Are the three declarations char **apple, char *apple[], and char apple[][] same?

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

9.

Which bitwise operator is suitable for turning off a particular bit in a number?

A.
&& operator
B.
& operator
C.
|| operator
D.
! operator

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

10.

In C all functions except main() can be called recursively.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Any function including main() can be called recursively.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

11.

What will be the output of the program?

#include<stdio.h>
int main()
{
    int i=2;
    int j = i + (1, 2, 3, 4, 5);
    printf("%d\n", j);
    return 0;
}

A.
4
B.
7
C.
6
D.
5

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Because, comma operator used in the expression i (1, 2, 3, 4, 5). The comma operator has left-right associativity. The left operand is always evaluated first, and the result of evaluation is discarded before the right operand is evaluated. In this expression 5 is the right most operand, hence after evaluating expression (1, 2, 3, 4, 5) the result is 5, which on adding to i results into 7.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

12.

What will be the output of the program?

#include<stdio.h>
int main()
{
    int i=-3, j=2, k=0, m;
    m = ++i && ++j && ++k;
    printf("%d, %d, %d, %d\n", i, j, k, m);
    return 0;
}

A.
-2, 3, 1, 1
B.
2, 3, 1, 2
C.
1, 2, 3, 1
D.
3, 3, 1, 2

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j && ++k;
becomes m = -2 && 3 && 1;
becomes m = TRUE && TRUE; Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j,k are increemented by '1'(one).

Hence the output is "-2, 3, 1, 1".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

13.

Two different operators would always have different Associativity.

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

No, Two different operators may have same associativity.

Example:
Arithmetic operators like ++, -- having Right-to-Left associativity.
Relational operators like >, >= also have Left-to-Right associativity.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

14.

Bitwise & can be used to divide a number by powers of 2

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

15.

Left shifting a number by 1 is always equivalent to multiplying it by 2.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

0001 => 1
0010 => 2
0100 => 4
1000 => 8

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

16.

A text stream is an ordered sequence of characters composed into lines, each line consisting of zero or more characters plus a terminating new-line character.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

True, each line may contain zero or more characters terminated by a newline character.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

17.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char str[] = "peace";
    char *s = str;
    printf("%s\n", s++ +3);
    return 0;
}

A.
peace
B.
eace
C.
ace
D.
ce

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

18.

Is it necessary that in a function which accepts variable argument list there should be at least be one fixed argument?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

19.

The macro va_start is used to initialise a pointer to the beginning of the list of fixed arguments.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

20.

What will be the output of the program?

#include<stdio.h>
int sumdig(int);
int main()
{
    int a, b;
    a = sumdig(123);
    b = sumdig(123);
    printf("%d, %d\n", a, b);
    return 0;
}
int sumdig(int n)
{
    int s, d;
    if(n!=0)
    {
        d = n%10;
        n = n/10;
        s = d+sumdig(n);
    }
    else
        return 0;
    return s;
}

A.
4, 4
B.
3, 3
C.
6, 6
D.
12, 12

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

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