Online C Programming Test - C Programming Test - Random



Loading...  Loading Test...

Instruction:

  • This is a FREE online test. DO NOT pay money to anyone to attend this test.
  • 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.

Is there any difference in the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Yes, we have to specify the data type of the parameter when declaring a function.

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum


2.

Which of the following sentences are correct about a for loop in a C program?
1: for loop works faster than a while loop.
2: All things that can be done using a for loop can also be done using a while loop.
3: for(;;); implements an infinite loop.
4: for loop can be used if we want statements in a loop get executed at least once.

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


3.

What will be the output of the program ?

#include<stdio.h>
int *check(static int, static int);

int main()
{
    int *c;
    c = check(10, 20);
    printf("%d\n", c);
    return 0;
}
int *check(static int i, static int j)
{
    int *p, *q;
    p = &i;
    q = &j;
    if(i >= 45)
        return (p);
    else
        return (q);
}

A.
10
B.
20
C.
Error: Non portable pointer conversion
D.
Error: cannot use static for function parameters

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum


4.

A preprocessor directive is a message from programmer to the preprocessor.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

True, the programmer tells the compiler to include the preprocessor when compiling.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum


5.

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


6.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char t;
    char *p1 = "India", *p2;
    p2=p1;
    p1 = "BIX";
    printf("%s %s\n", p1, p2);
    return 0;
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Step 1: char *p1 = "India", *p2; The variable p1 and p2 is declared as an pointer to a character value and p1 is assigned with a value "India".

Step 2: p2=p1; The value of p1 is assigned to variable p2. So p2 contains "India".

Step 3: p1 = "BIX"; The p1 is assigned with a string "BIX"

Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2.

Hence the output of the program is "BIX India".

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum


7.

What is the similarity between a structure, union and enumeration?

A.
All of them let you define new values
B.
All of them let you define new data types
C.
All of them let you define new pointers
D.
All of them let you define new structures

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum


8.

Which of the following statements are correct about the program below?

#include<stdio.h>

int main()
{
    char str[20], *s;
    printf("Enter a string\n");
    scanf("%s", str);
    s=str;
    while(*s != '\0')
    {
        if(*s >= 97 && *s <= 122)
            *s = *s-32;
        s++;
    }
    printf("%s",str);
    return 0;
}

A.
The code converts a string in to an integer
B.
The code converts lower case character to upper case
C.
The code converts upper case character to lower case
D.
Error in code

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

This program converts the given string to upper case string.

Output:

Enter a string: indiabix

INDIABIX

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum


9.

Point out the error in the following program.

#include<stdio.h>
int main()
{
    int (*p)() = fun;
    (*p)();
    return 0;
}
int fun()
{
    printf("IndiaBix.com\n");
    return 0;
}

A.
Error: in int(*p)() = fun;
B.
Error: fun() prototype not defined
C.
No error
D.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The compiler will not know that the function int fun() exists. So we have to define the function prototype of int fun();
To overcome this error, see the below program


#include<stdio.h>
int fun(); /* function prototype */

int main()
{
    int (*p)() = fun;
    (*p)();
    return 0;
}
int fun()
{
    printf("IndiaBix.com\n");
    return 0;
}

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum


10.

If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?

#include<stdio.h>
#include<math.h>
int main()
{
    float a=5.375;
    char *p;
    int i;
    p = (char*)&a;
    for(i=0; i<=3; i++)
        printf("%02x\n", (unsigned char)p[i]);
    return 0;
}

A.
40 AC 00 00
B.
04 CA 00 00
C.
00 00 AC 40
D.
00 00 CA 04

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum


11.

What will you do to treat the constant 3.14 as a float?

A.
use float(3.14f)
B.
use 3.14f
C.
use f(3.14)
D.
use (f)(3.14)

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Given 3.14 is a double constant.
To specify 3.14 as float, we have to add f to the 3.14. (i.e 3.14f)

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum


12.

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


13.

Out of fgets() and gets() which function is safe to use?

A.
gets()
B.
fgets()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Because, In fgets() we can specify the size of the buffer into which the string supplied will be stored.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum


14.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    struct byte
    {
        int one:1;
    };
    struct byte var = {1};
    printf("%d\n", var.one);
    return 0;
}

A.
1
B.
-1
C.
0
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum


15.

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


16.

Point out the error, if any in the program.

#include<stdio.h>
int main()
{
    int P = 10;
    switch(P)
    {
       case 10:
       printf("Case 1");

       case 20:
       printf("Case 2");
       break;

       case P:
       printf("Case 2");
       break;
    }
    return 0;
}

A.
Error: No default value is specified
B.
Error: Constant expression required at line case P:
C.
Error: There is no break statement in each case.
D.
No error will be reported.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The compiler will report the error "Constant expression required" in the line case P: . Because, variable names cannot be used with case statements.

The case statements will accept only constant expression.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


17.

Point out the error in the program?

#include<stdio.h>

int main()
{
    struct emp
    {
        char n[20];
        int age;
    };
    struct emp e1 = {"Dravid", 23};
    struct emp e2 = e1;
    if(e1 == e2)
        printf("The structure are equal");
    return 0;
}

A.
Prints: The structure are equal
B.
Error: Structure cannot be compared using '=='
C.
No output
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


18.

What will be the output of the program in DOS (Compiler - Turbo C)?

#include<stdio.h>
double i;

int main()
{
    (int)(float)(char) i;
    printf("%d",sizeof(i));
    return 0;
}

A.
4
B.
8
C.
16
D.
22

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum


19.

What will be the output of the program?

#include<stdio.h>

int main()
{
    int y=128;
    const int x=y;
    printf("%d\n", x);
    return 0;
}

A.
128
B.
Garbage value
C.
Error
D.
0

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: int y=128; The variable 'y' is declared as an integer type and initialized to value "128".

Step 2: const int x=y; The constant variable 'x' is declared as an integer and it is initialized with the variable 'y' value.

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

Hence the output of the program is "128"

Learn more problems on : Const

Discuss about this problem : Discuss in Forum


20.

malloc() returns a NULL if it fails to allocate the requested memory.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum


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