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.

Point out the error in the program?

#include<stdio.h>

int main()
{
    union a
    {
        int i;
        char ch[2];
    };
    union a z1 = {512};
    union a z2 = {0, 2};
    return 0;
}

A.
Error: invalid union declaration
B.
Error: in Initializing z2
C.
No error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

2.

What will be the output of the program?

#include<stdio.h>
#define FUN(arg) do\
                 {\
                    if(arg)\
                        printf("IndiaBIX...", "\n");\
                  }while(--i)

int main()
{
    int i=2;
    FUN(i<3);
    return 0;
}

A.
IndiaBIX...
IndiaBIX...
IndiaBIX
B.
IndiaBIX... IndiaBIX...
C.
Error: cannot use control instructions in macro
D.
No output

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied.

Step 1: int i=2; The variable i is declared as an integer type and initialized to 2.

Step 2: FUN(i<3); becomes,

do
{
    if(2 < 3)
    printf("IndiaBIX...", "\n");
}while(--2)

After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks.

Hence the output of the program is "IndiaBIX... IndiaBIX..."

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

3.

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

4.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    printf(5+"IndiaBIX\n");
    return 0;
}

A.
Error
B.
IndiaBIX
C.
BIX
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

printf(5+"IndiaBIX\n"); In the printf statement, it skips the first 5 characters and it prints "BIX"

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

5.

What will be the output of the program in Turbo C?

#include<stdio.h>

int main()
{
    char str[10] = "India";
    str[6] = "BIX";
    printf("%s\n", str);
    return 0;
}

A.
India BIX
B.
BIX
C.
India
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

str[6] = "BIX"; - Nonportable pointer conversion.

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

6.

Are the expressions arr and &arr same for an array of 10 integers?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

7.

Which of the following statements are correct about an array?
1: The array int num[26]; can store 26 elements.
2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration.
4: The declaration num[SIZE] is allowed if SIZE is a macro.

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

1. The array int num[26]; can store 26 elements. This statement is true.

2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.

3. It is necessary to initialize the array at the time of declaration. This statement is false.

4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.

Hence the statements '1' and '4' are correct statements.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

8.

What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

#include<stdio.h>

int main()
{
    int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
    return 0;
}

A.
448, 4, 4
B.
520, 2, 2
C.
1006, 2, 2
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

9.

What will be the output of the program?

#include<stdio.h>
#include<stdarg.h>
void display(int num, ...);

int main()
{
    display(4, 'A', 'B', 'C', 'D');
    return 0;
}
void display(int num, ...)
{
    char c, c1; int j;
    va_list ptr, ptr1;
    va_start(ptr, num);
    va_start(ptr1, num);
    for(j=1; j<=num; j++)
    {
        c = va_arg(ptr, int);
        printf("%c", c);
        c1 = va_arg(ptr1, int);
        printf("%d\n", c1);
    }
}

A.
A, A
B, B
C, C
D, D
B.
A, a
B, b
C, c
D, d
C.
A, 65
B, 66
C, 67
D, 68
D.
A, 0
B, 0
C, 0
C, 0

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

10.

In a function that receives variable number of arguments the fixed arguments passed to the function can be at the end of argument list.

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

11.

Point out the correct statement which correctly allocates memory dynamically for 2D array following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p, i, j;
    /* Add statement here */
    for(i=0; i<3; i++)
    {
        for(j=0; j<4; j++)
        {
            p[i*4+j] = i;
            printf("%d", p[i*4+j]);
        }
    }
    return 0;
}

A.
p = (int*) malloc(3, 4);
B.
p = (int*) malloc(3*sizeof(int));
C.
p = malloc(3*4*sizeof(int));
D.
p = (int*) malloc(3*4*sizeof(int));

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

12.

The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

False, the preprocessor cannot trap the errors, it only replaces the macro with the given expression. But the compiler will detect errors.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

13.

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

14.

What will be the output of the program in Turbo C?

#include<stdio.h>

int main()
{
    char near *near *ptr1;
    char near *far *ptr2;
    char near *huge *ptr3;
    printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
}

A.
4, 4, 8
B.
4, 4, 4
C.
2, 4, 8
D.
2, 4, 4

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

15.

What will be the output of the program?

#include<stdio.h>

int main()
{
    enum color{red, green, blue};
    typedef enum color mycolor;
    mycolor m = red;
    printf("%d", m);
    return 0;
}

A.
1
B.
0
C.
2
D.
red

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

16.

If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?

A.
.
B.
&
C.
*
D.
->

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

17.

In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The equal to = operator has Right-to-Left Associativity. So it assigns b=5 then a=b.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

18.

Point out the error in the program

#include<stdio.h>

int main()
{
    int a[] = {10, 20, 30, 40, 50};
    int j;
    for(j=0; j<5; j++)
    {
        printf("%d\n", a);
        a++;
    }
    return 0;
}

A.
Error: Declaration syntax
B.
Error: Expression syntax
C.
Error: LValue required
D.
Error: Rvalue required

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

19.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char *p;
    p="%d\n";
    p++;
    p++;
    printf(p-2, 23);
    return 0;
}

A.
21
B.
23
C.
Error
D.
No output

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

20.

Offset used in fseek() function call can be a negative number.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

True, offset in fseek() function can be a negative number. It makes the file pointer to move backwards from the current position.

Declaration: retval = fseek( fp, offset, from );

Where:

FILE *fp; = points to the file on which I/O is to be repositioned.

long offset; = is an integer giving the number of bytes to move forward or backward in the file. This may be positive or negative.

int from; = is one of the manifests SEEK_SET, SEEK_CUR, or SEEK_END.

int retval; = is non-zero if the seek operation was invalid (e.g. on a file not opened with a "b" option); otherwise, the return value is zero.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

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


Have a question?

Ask your question now !