# Online C Programming Test - C Programming Test 5 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 : 20 minutes.
• Each question carry 1 mark, no negative marks.
• DO NOT refresh the page.
• All the best :-).

1.

The modulus operator cannot be used with a long double.

A.
 True B.
 False Correct Answer: Option A

Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point or long double divisions.

Learn more problems on : Control Instructions

2.

What will be the output of the program?

``````#include<stdio.h>
int main()
{
int i=-3, j=2, k=0, m;
m = ++i && ++j && ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
``````

A.
 -2, 3, 1, 1 B.
 2, 3, 1, 2 C.
 1, 2, 3, 1 D.
 3, 3, 1, 2 Correct Answer: Option A

Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j && ++k;
becomes m = -2 && 3 && 1;
becomes m = TRUE && TRUE; Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j,k are increemented by '1'(one).

Hence the output is "-2, 3, 1, 1".

3.

In a function two return statements should never occur.

A.
 Yes B.
 No Correct Answer: Option B

Explanation:

No, In a function two return statements can occur but not successively.

Example:

``````
#include <stdio.h>
int mul(int, int); /* Function prototype */

int main()
{
int a = 0, b = 3, c;
c = mul(a, b);
printf("c = %d\n", c);
return 0;
}

/* Two return statements in the mul() function */
int mul(int a, int b)
{
if(a == 0 || b == 0)
{
return 0;
}
else
{
return (a * b);
}
}
``````

Output:
c = 0

4.

It is necessary that a header files should have a .h extension?

A.
 Yes B.
 No Correct Answer: Option B

Explanation:

No, the header files have any kind of extension.

Learn more problems on : C Preprocessor

5.

How many bytes are occupied by near, far and huge pointers (DOS)?

A.
 near=2 far=4 huge=4 B.
 near=4 far=8 huge=8 C.
 near=2 far=4 huge=8 D.
 near=4 far=4 huge=8 Correct Answer: Option A

Explanation:

near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4 bytes long.

6.

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 Correct Answer: Option D

7.

What will be the output of the program ?

``````#include<stdio.h>

int main()
{
void *vp;
char ch=74, *cp="JACK";
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c", *(int*)vp);
vp=cp;
printf("%s", (char*)vp+2);
return 0;
}
``````

A.
 JCK B.
 J65K C.
 JAK D.
 JACK Correct Answer: Option D

8.

Which of the statements is correct about the program?

``````#include<stdio.h>

int main()
{
int arr = {1, 2, 3, 4};
printf("%d\n", *(*(*(arr))));
return 0;
}
``````

A.
 Output: Garbage value B.
 Output: 1 C.
 Output: 3 D.
 Error: Invalid indirection Correct Answer: Option D

9.

What will be the output of the program ?

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

int main()
{
char str[] = "India\0\BIX\0";
printf("%s\n", str);
return 0;
}
``````

A.
 BIX B.
 India C.
 India BIX D.
 India\0BIX Correct Answer: Option B

Explanation:

A string is a collection of characters terminated by '\0'.

Step 1: char str[] = "India\0\BIX\0"; The variable str is declared as an array of characters and initialized with value "India"

Step 2: printf("%s\n", str); It prints the value of the str.

The output of the program is "India".

10.

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

``````#include<stdio.h>

int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
``````

A.
 Error: Invalid structure assignment B.
 DRAVID C.
 Dravid D.
 No output Correct Answer: Option B

Learn more problems on : Structures, Unions, Enums

11.

Point out the error in the program?

``````#include<stdio.h>

int main()
{
struct a
{
float category:5;
char scheme:4;
};
printf("size=%d", sizeof(struct a));
return 0;
}
``````

A.
 Error: invalid structure member in printf B.
 Error in this float category:5; statement C.
 No error D.
 None of above Correct Answer: Option B

Explanation:

Bit field type must be signed int or unsigned int.

The char type: char scheme:4; is also a valid statement.

Learn more problems on : Structures, Unions, Enums

12.

Point out the error in the program?

``````#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
char name;
int age;
};
int main()
{
struct emp e = {"Sanjay", 35};
modify(&e);
printf("%s %d", e.name, e.age);
return 0;
}
void modify(struct emp *p)
{
p ->age=p->age+2;
}
``````

A.
 Error: in structure B.
 Error: in prototype declaration unknown struct emp C.
 No error D.
 None of above Correct Answer: Option B

Explanation:

The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.

Learn more problems on : Structures, Unions, Enums

13.

The '.' operator can be used access structure elements using a structure variable.

A.
 True B.
 False Correct Answer: Option A

Learn more problems on : Structures, Unions, Enums

14.

Can we specify a variable filed width in a scanf() format string?

A.
 Yes B.
 No Correct Answer: Option B

Explanation:

In scanf() a * in a format string after a % sign is used for the suppression of assignment. That is, the current input field is scanned but not stored.

Learn more problems on : Input / Output

15.

Which header file should be included to use functions like malloc() and calloc()?

A.
 memory.h B.
 stdlib.h C.
 string.h D.
 dos.h Correct Answer: Option B

Learn more problems on : Memory Allocation

16.

If malloc() successfully allocates memory it returns the number of bytes it has allocated.

A.
 True B.
 False Correct Answer: Option B

Explanation:

Syntax: void *malloc(size_t size);

The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.

The order and contiguity of storage allocated by successive calls to malloc() is unspecified. The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned. If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer.

Learn more problems on : Memory Allocation

17.

In a function that receives variable number of arguments the fixed arguments passed to the function can be at the end of argument list.

A.
 True B.
 False Correct Answer: Option B

Learn more problems on : Variable Number of Arguments

18.

We can allocate a 2-Dimensional array dynamically.

A.
 True B.
 False Correct Answer: Option A

Learn more problems on : Complicated Declarations

19.

Are the following declarations same?

``````char far *far *scr;
char far far** scr;
``````

A.
 Yes B.
 No Correct Answer: Option B

Learn more problems on : Complicated Declarations

20.

What is the purpose of fflush() function.

A.
 flushes all streams and specified streams. B.
 flushes only specified stream. C.
 flushes input/output buffer. D.
 flushes file buffer. Correct Answer: Option A

Explanation:

"fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell command for redirecting output to a pipe or coprocess.

Example:
fflush(FilePointer);
fflush(NULL); flushes all streams.

Learn more problems on : Library Functions