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.

If the different command line arguments are supplied at different times would the output of the following program change?

#include<stdio.h>

int main(int argc, char **argv)
{
    printf("%d\n", argv[argc]);
    return 0;
}

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum


2.

Which statement will you add in the following program to work it correctly?

#include<stdio.h>
int main()
{
    printf("%f\n", log(36.0));
    return 0;
}

A.
#include<conio.h>
B.
#include<math.h>
C.
#include<stdlib.h>
D.
#include<dos.h>

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

math.h is a header file in the standard library of C programming language designed for basic mathematical operations.

Declaration syntax: double log(double);

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum


3.

What function should be used to free the memory allocated by calloc() ?

A.
dealloc();
B.
malloc(variable_name, 0)
C.
free();
D.
memalloc(variable_name, 0)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum


4.

What is the output of the program

#include<stdio.h>
int main()
{
    int x = 10, y = 20, z = 5, i;
    i = x < y < z;
    printf("%d\n", i);
    return 0;
}

A.
0
B.
1
C.
Error
D.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to be TRUE. The 1 is assigned to i.

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum


5.

What will be the output of the program?

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

int main()
{
    fun1(1, "Apple", "Boys", "Cats", "Dogs");
    fun2(2, 12, 13, 14);
    return 0;
}
void fun1(int num, ...)
{
    char *str;
    va_list ptr;
    va_start(ptr, num);
    str = va_arg(ptr, char *);
    printf("%s ", str);
}
void fun2(int num, ...)
{
    va_list ptr;
    va_start(ptr, num);
    num = va_arg(ptr, int);
    printf("%d", num);
}

A.
Dogs 12
B.
Cats 14
C.
Boys 13
D.
Apple 12

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum


6.

Point out the error in the program

#include<stdio.h>

int main()
{
    int a=10;
    void f();
    a = f();
    printf("%d\n", a);
    return 0;
}
void f()
{
    printf("Hi");
}

A.
Error: Not allowed assignment
B.
Error: Doesn't print anything
C.
No error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The function void f() is not visible to the compiler while going through main() function. So we have to declare this prototype void f(); before to main() function. This kind of error will not occur in modern compilers.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


7.

Point out the error in the program

#include<stdio.h>
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;
}

A.
Error: Prototype declaration
B.
No error
C.
Error: return statement cannot be used with conditional operators
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

In a ternary operator, we cannot use the return statement. The ternary operator requires expressions but not code.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


8.

What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
    static char str1[] = "dills";
    static char str2[20];
    static char str3[] = "Daffo";
    int i;
    i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
    printf("%d\n", i);
    return 0;
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum


9.

typedef's have the advantage that they obey scope rules, that is they can be declared local to a function or a block whereas #define's always have a global effect.

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum


10.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    FILE *fp;
    char ch, str[7];
    fp=fopen("try.c", "r"); /* file 'try.c' contains "This is Nagpur" */
    fseek(fp, 9L, SEEK_CUR);
    fgets(str, 5, fp);
    puts(str);
    return 0;
}

A.
agpur
B.
gpur
C.
Nagp
D.
agpu

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum


11.

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


12.

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


13.

What will be the output of the program in 16 bit platform (Turbo C under DOS)?

#include<stdio.h>

int main()
{
    int fun();
    int i;
    i = fun();
    printf("%d\n", i);
    return 0;
}
int fun()
{
    _AX = 1990;
}

A.
Garbage value
B.
0 (Zero)
C.
1990
D.
No output

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Turbo C (Windows): The return value of the function is taken from the Accumulator _AX=1990.

But it may not work as expected in GCC compiler (Linux).

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


14.

What will be the output of the program?

#include<stdio.h>

int main()
{
    int i=1;
    if(!i)
        printf("IndiaBIX,");
    else
    {
        i=0;
        printf("C-Program");
        main();
    }
    return 0;
}

A.
prints "IndiaBIX, C-Program" infinitely
B.
prints "C-Program" infinetly
C.
prints "C-Program, IndiaBIX" infinitely
D.
Error: main() should not inside else statement

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

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

Step 2: if(!i) Here the !(NOT) operator reverts the i value 1 to 0. Hence the if(0) condition fails. So it goes to else part.

Step 3: else { i=0; In the else part variable i is assigned to value 0(zero).

Step 4: printf("C-Program"); It prints the "C-program".

Step 5: main(); Here we are calling the main() function.

After calling the function, the program repeats from step 1 to step 5 infinitely.

Hence it prints "C-Program" infinitely.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


15.

What will be the output of the program in 16-bit platform (under DOS)?

#include<stdio.h>

int main()
{
    struct node
    {
        int data;
        struct node *link;
    };
    struct node *p, *q;
    p = (struct node *) malloc(sizeof(struct node));
    q = (struct node *) malloc(sizeof(struct node));
    printf("%d, %d\n", sizeof(p), sizeof(q));
    return 0;
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum


16.

Every time we supply new set of values to the program at command prompt, we need to recompile the program.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum


17.

To print out a and b given below, which of the following printf() statement will you use?

#include<stdio.h>

float a=3.14;
double b=3.14;

A.
printf("%f %lf", a, b);
B.
printf("%Lf %f", a, b);
C.
printf("%Lf %Lf", a, b);
D.
printf("%f %Lf", a, b);

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

To print a float value, %f is used as format specifier.

To print a double value, %lf is used as format specifier.

Therefore, the answer is printf("%f %lf", a, b);

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum


18.

Point out the correct statement will let you access the elements of the array using 'p' in the following program?

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

int main()
{
    int i, j;
    int(*p)[3];
    p = (int(*)[3])malloc(3*sizeof(*p));
    return 0;
}

A.
for(i=0; i<3; i++)
{
    for(j=0; j<3; j++)
        printf("%d", p[i+j]);
}
B.
for(i=0; i<3; i++)
    printf("%d", p[i]);
C.
for(i=0; i<3; i++)
{
    for(j=0; j<3; j++)
        printf("%d", p[i][j]);
}
D.
for(j=0; j<3; j++)
    printf("%d", p[i][j]);

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum


19.

Bitwise can be used to generate a random number.

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum


20.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    static char *s[] = {"black", "white", "pink", "violet"};
    char **ptr[] = {s+3, s+2, s+1, s}, ***p;
    p = ptr;
    ++p;
    printf("%s", **p+1);
    return 0;
}

A.
ink
B.
ack
C.
ite
D.
let

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum


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