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 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

2.

If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>

int main()
{
    unsigned int m = 32;
    printf("%x\n", ~m);
    return 0;
}

A.
ffff
B.
0000
C.
ffdf
D.
ddfd

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

3.

What will be the output of the program?

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

int main()
{
    int *p;
    p = (int *)malloc(20); /* Assume p has address of 1314 */
    free(p);
    printf("%u", p);
    return 0;
}

A.
1314
B.
Garbage value
C.
1316
D.
Random address

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
int main()
{
    int X=40;
    {
        int X=20;
        printf("%d ", X);
    }
    printf("%d\n", X);
    return 0;
}

A.
40 40
B.
20 40
C.
20
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

In case of a conflict between a local variable and global variable, the local variable gets priority.

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>

int main()
{
    int x=30, *y, *z;
    y=&x; /* Assume address of x is 500 and integer is 4 byte size */
    z=y;
    *y++=*z++;
    x++;
    printf("x=%d, y=%d, z=%d\n", x, y, z);
    return 0;
}

A.
x=31, y=502, z=502
B.
x=31, y=500, z=500
C.
x=31, y=498, z=498
D.
x=31, y=504, z=504

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

6.

Can the fixed arguments passed to the function that accepts variable argument list, occur at the end?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

7.

What will be the output of the program?

#include<stdio.h>
int main()
{
    char str[]="C-program";
    int a = 5;
    printf(a >10?"Ps\n":"%s\n", str);
    return 0;
}

A.
C-program
B.
Ps
C.
Error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: char str[]="C-program"; here variable str contains "C-program".
Step 2: int a = 5; here variable a contains "5".
Step 3: printf(a >10?"Ps\n":"%s\n", str); this statement can be written as


if(a > 10)
{
    printf("Ps\n");
}
else
{
    printf("%s\n", str);
}

Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str.

Hence the output is "C-program".

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

8.

Will it result in to an error if a header file is included twice?

A.
Yes
B.
No
C.
It is compiler dependent.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Unless the header file has taken care to ensure that if already included it doesn't get included again.

Turbo C, GCC compilers would take care of these problems, generate no error.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

9.

What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample Jan Feb Mar

/* sample.c */
#include<stdio.h>
#include<dos.h>

int main(int arc, char *arv[])
{
    int i;
    for(i=1; i<_argc; i++)
        printf("%s ", _argv[i]);
    return 0;
}

A.
No output
B.
sample Jan Feb Mar
C.
Jan Feb Mar
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

10.

Which of the following statements correctly declare a function that receives a pointer to pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float?

A.
float **fun(float***);
B.
float *fun(float**);
C.
float fun(float***);
D.
float ****fun(float***);

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

11.

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

12.

What will be the output of the program?

#include<stdio.h>
int i;
int fun();

int main()
{
    while(i)
    {
        fun();
        main();
    }
    printf("Hello\n");
    return 0;
}
int fun()
{
    printf("Hi");
}

A.
Hello
B.
Hi Hello
C.
No output
D.
Infinite loop

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

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

Step 1: int fun(); This prototype tells the compiler that the function fun() does not accept any arguments and it returns an integer value.

Step 1: while(i) The value of i is not initialized so this while condition is failed. So, it does not execute the while block.

Step 1: printf("Hello\n"); It prints "Hello".

Hence the output of the program is "Hello".

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

13.

What will be the output of the program?

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

int main()
{
    fun(main);
    printf("Hi\n");
    return 0;
}
int fun(int (*p)())
{
    printf("Hello ");
    return 0;
}

A.
Infinite loop
B.
Hi
C.
Hello Hi
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

14.

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

15.

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

16.

Data written into a file using fwrite() can be read back using fscanf()

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

17.

In the following code snippet can we declare a new typedef named ptr even though struct employee has not been completely declared while using typedef?

typedef struct employee *ptr;
struct employee
{
    char name[20];
    int age;
    ptr next;
}

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

18.

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

19.

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

20.

A function that receives variable number of arguments should use va_arg() to extract arguments from the variable argument list.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

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