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.

The following program reports an error on compilation.

#include<stdio.h>
int main()
{
    float i=10, *j;
    void *k;
    k=&i;
    j=k;
    printf("%f\n", *j);
    return 0;
}

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

This program will NOT report any error. (Tested in Turbo C under DOS and GCC under Linux)

The output: 10.000000

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

2.

Which of the following special symbol allowed in a variable name?

A.
* (asterisk)
B.
| (pipeline)
C.
- (hyphen)
D.
_ (underscore)

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit.

Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=> foo_bar
=> _foo42
=> _
=> QuUx

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

3.

Point out the error, if any in the program.

#include<stdio.h>
int main()
{
    int i = 1;
    switch(i)
    {
        printf("This is c program.");
        case 1:
            printf("Case1");
            break;
        case 2:
            printf("Case2");
            break;
    }
return 0;
}

A.
Error: No default specified
B.
Error: Invalid printf statement after switch statement
C.
No Error and prints "Case1"
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints "Case1".

printf("This is c program."); is ignored by the compiler.

Hence there is no error and prints "Case1".

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

4.

Function can return a floating point number.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

5.

What will be the output of the program ?

#include<stdio.h>
char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}";

int main()
{
    printf(str, 34, str, 34);
    return 0;
}

A.
char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}"; main(){ printf(str, 34, str, 34);}
B.
char *str = %c%s%c; main(){ printf(str, 34, str, 34);}
C.
No output
D.
Error in program

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

6.

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

7.

Every C program will contain at least one preprocessor directive.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

False, the preprocessor directive is not mandatory in any c program.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

8.

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

A.
use 3.14LD
B.
use 3.14L
C.
use 3.14DL
D.
use 3.14LF

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Given 3.14 is a double constant.

To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L)

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum

9.

What will be the output of the program?

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

int main()
{
    union test
    {
        int i;
        float f;
        char c;
    };
    union test *t;
    t = (union test *)malloc(sizeof(union test));
    t->f = 10.10f;
    printf("%f", t->f);
    return 0;
}

A.
10
B.
Garbage value
C.
10.100000
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

10.

Assume integer is 2 bytes wide. How many bytes will be allocated for the following code?

#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4

int main()
{
    int (*p)[MAXCOL];
    p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p));
    return 0;
}

A.
56 bytes
B.
128 bytes
C.
24 bytes
D.
12 bytes

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

11.

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

12.

The expression of the right hand side of || operators doesn't get evaluated if the left hand side determines the outcome.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Because, if a is non-zero then b will not be evaluated in the expression (a || b)

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

13.

What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample monday tuesday wednesday thursday

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

int main(int argc, char *argv[])
{
    while(--argc>0)
        printf("%s", *++argv);
    return 0;
}

A.
sample monday tuesday wednesday thursday
B.
monday tuesday wednesday thursday
C.
monday tuesday thursday
D.
tuesday

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

14.

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

15.

What will be the output of the program?

#include<stdio.h>
#define SWAP(a, b) int t; t=a, a=b, b=t;
int main()
{
    int a=10, b=12;
    SWAP(a, b);
    printf("a = %d, b = %d\n", a, b);
    return 0;
}

A.
a = 10, b = 12
B.
a = 12, b = 10
C.
Error: Declaration not allowed in macro
D.
Error: Undefined symbol 't'

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The macro SWAP(a, b) int t; t=a, a=b, b=t; swaps the value of the given two variable.

Step 1: int a=10, b=12; The variable a and b are declared as an integer type and initialized to 10, 12 respectively.

Step 2: SWAP(a, b);. Here the macro is substituted and it swaps the value to variable a and b.

Hence the output of the program is 12, 10.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

16.

Which of the following statements correct about k used in the below statement?
char ****k;

A.
k is a pointer to a pointer to a pointer to a char
B.
k is a pointer to a pointer to a pointer to a pointer to a char
C.
k is a pointer to a char pointer
D.
k is a pointer to a pointer to a char

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

17.

If the two strings are identical, then strcmp() function returns

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Declaration: strcmp(const char *s1, const char*s2);

The strcmp return an int value that is

if s1 < s2 returns a value < 0

if s1 == s2 returns 0

if s1 > s2 returns a value > 0

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

18.

Point out the error in the following program.

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

int main()
{
    char *ptr;
    *ptr = (char)malloc(30);
    strcpy(ptr, "RAM");
    printf("%s", ptr);
    free(ptr);
    return 0;
}

A.
Error: in strcpy() statement.
B.
Error: in *ptr = (char)malloc(30);
C.
Error: in free(ptr);
D.
No error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Answer: ptr = (char*)malloc(30);

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

19.

Bitwise | can be used to set multiple bits in number.

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

20.

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

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


Have a question?

Ask your question now !