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>
#define SI(p, n, r) float si; si=p*n*r/100;
int main()
{
    float p=2500, r=3.5;
    int n=3;
    SI(p, n, r);
    SI(1500, 2, 2.5);
    return 0;
}

A.
26250.00 7500.00
B.
Nothing will print
C.
Error: Multiple declaration of si
D.
Garbage values

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The macro #define SI(p, n, r) float si; si=p*n*r/100; contains the error. To remove this error, we have to modify this macro to

#define SI(p,n,r) p*n*r/100

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

2.

In the following program add a statement in the function fun() such that address of a gets stored in j?

#include<stdio.h>
int main()
{
    int *j;
    void fun(int**);
    fun(&j);
    return 0;
}
void fun(int **k)
{
    int a=10;
    /* Add a statement here */
}

A.
**k=a;
B.
k=&a;
C.
*k=&a
D.
&k=*a

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

3.

Will the program compile?

#include<stdio.h>
int main()
{
    char str[5] = "IndiaBIX";
    return 0;
}

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

C doesn't do array bounds checking at compile time, hence this compiles.

But, the modern compilers like Turbo C++ detects this as 'Error: Too many initializers'.

GCC would give you a warning.

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

4.

Can we write a function that takes a variable argument list and passes the list to another function?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

5.

Can you use the fprintf() to display the output on the screen?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Do like this fprintf(stdout, "%s %d %f", str, i, a);

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

6.

What will be the output of the program given below in 16-bit platform ?

#include<stdio.h>

int main()
{
    enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var;
    printf("%d\n", sizeof(var));
    return 0;
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

7.

Point out the error in the following program.

#include<stdio.h>
struct emp
{
    char name[20];
    int age;
};
int main()
{
    emp int xx;
    int a;
    printf("%d\n", &a);
    return 0;
}

A.
Error: in printf
B.
Error: in emp int xx;
C.
No error.
D.
None of these.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

There is an error in the line emp int xx;

To overcome this error, remove the int and add the struct at the begining of emp int xx;

#include<stdio.h>
struct emp
{
    char name[20];
    int age;
};
int main()
{
    struct emp xx;
    int a;
    printf("%d\n", &a);
    return 0;
}

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

8.

What will be the output of the program?

#include<stdio.h>

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

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

9.

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

10.

What will be the output of the program?

#include<stdio.h>
#define SQUARE(x) x*x

int main()
{
    float s=10, u=30, t=2, a;
    a = 2*(s-u*t)/SQUARE(t);
    printf("Result = %f", a);
    return 0;
}

A.
Result = -100.000000
B.
Result = -25.000000
C.
Result = 0.000000
D.
Result = 100.000000

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The macro function SQUARE(x) x*x calculate the square of the given number 'x'. (Eg: 102)

Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating point type and the variable s, u, t are initialized to 10, 30, 2.

Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,

=> a = 2 * (10 - 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .

=> a = 2 * (10 - 30 * 2) / 2 * 2;

=> a = 2 * (10 - 60) / 2 * 2;

=> a = 2 * (-50) / 2 * 2 ;

=> a = 2 * (-25) * 2 ;

=> a = (-50) * 2 ;

=> a = -100;

Step 3: printf("Result=%f", a); It prints the value of variable 'a'.

Hence the output of the program is -100

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

11.

Point out the error in the program?

#include<stdio.h>

int main()
{
    struct emp
    {
        char name[20];
        float sal;
    };
    struct emp e[10];
    int i;
    for(i=0; i<=9; i++)
        scanf("%s %f", e[i].name, &e[i].sal);
    return 0;
}

A.
Error: invalid structure member
B.
Error: Floating point formats not linked
C.
No error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

At run time it will show an error then program will be terminated.

Sample output: Turbo C (Windows)

c:\>myprogram
                                                          
Sample
12.123

scanf : floating point formats not linked 
Abnormal program termination 

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

12.

In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?

A.
"I am a boy\r\n\0"
B.
"I am a boy\r\0"
C.
"I am a boy\n\0"
D.
"I am a boy"

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Declaration: char *fgets(char *s, int n, FILE *stream);

fgets reads characters from stream into the string s. It stops when it reads either n - 1 characters or a newline character, whichever comes first.

Therefore, the string str contain "I am a boy\n\0"

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

13.

Which of the following statement is True?

A.
User has to explicitly define the numeric value of enumerations
B.
User has a control over the size of enumeration variables.
C.
Enumeration can have an effect local to the block, if desired
D.
Enumerations have a global effect throughout the file.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

14.

What do the following declaration signify?

int (*pf)();

A.
pf is a pointer to function.
B.
pf is a function pointer.
C.
pf is a pointer to a function which return int
D.
pf is a function of pointer variable.

Your Answer: Option (Not Answered)

Correct Answer: Option C

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>
power(int**);
int main()
{
    int a=5, *aa; /* Address of 'a' is 1000 */
    aa = &a;
    a = power(&aa);
    printf("%d\n", a);
    return 0;
}
power(int **ptr)
{
    int b;
    b = **ptr***ptr;
    return (b);
}

A.
5
B.
25
C.
125
D.
Garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

16.

If the size of integer is 4bytes, What will be the output of the program?

#include<stdio.h>

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}

A.
10, 2, 4
B.
20, 4, 4
C.
16, 2, 2
D.
20, 2, 2

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

17.

What will be the output of the program?

#include<stdio.h>
int main()
{
    int i=0;
    for(; i<=5; i++);
        printf("%d", i);
    return 0;
}

A.
0, 1, 2, 3, 4, 5
B.
5
C.
1, 2, 3, 4
D.
6

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Step 1: int i = 0; here variable i is an integer type and initialized to '0'.
Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous step. The semi-colon at the end of this for loop tells, "there is no more statement is inside the loop".

Loop 1: here i=0, the condition in for(; 0<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by '1'(one)
Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is not incremented.

Step 3: printf("%d", i); here the value of i is 6. Hence the output is '6'.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

18.

What do the 'c' and 'v' in argv stands for?

A.
'c' means argument control 'v' means argument vector
B.
'c' means argument count 'v' means argument vertex
C.
'c' means argument count 'v' means argument vector
D.
'c' means argument configuration 'v' means argument visibility

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

19.

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

20.

Point out the error in the following program.

#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
void show(char *t, ...);

int main()
{
    display("Hello", 4, 12, 13, 14, 44);
    return 0;
}
void display(char *s, ...)
{
    show(s, ...);
}
void show(char *t, ...)
{
    int a;
    va_list ptr;
    va_start(ptr, s);
    a = va_arg(ptr, int);
    printf("%f", a);
}

A.
Error: invalid function display() call
B.
Error: invalid function show() call
C.
No error
D.
Error: Rvalue required for t

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The call to show() is improper. This is not the way to pass variable argument list to a function.

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.


Have a question?

Ask your question now !