Online C Programming Test - C Programming Test 5

Instruction:

  • This is a FREE online test. Beware of scammers who ask for money to attend this test.
  • Total number of questions: 20.
  • Time allotted: 20 minutes.
  • Each question carries 1 mark; there are no negative marks.
  • DO NOT refresh the page.
  • All the best!

Marks : 2/20


Total number of questions
20
Number of answered questions
0
Number of unanswered questions
20
Test Review : View answers and explanation for this test.

1.
The modulus operator cannot be used with a long double.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
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.


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;
}
-2, 3, 1, 1
2, 3, 1, 2
1, 2, 3, 1
3, 3, 1, 2
Your Answer: Option
(Not Answered)
Correct Answer: Option
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.
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
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?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

No, the header files have any kind of extension.


5.
How many bytes are occupied by near, far and huge pointers (DOS)?
near=2 far=4 huge=4
near=4 far=8 huge=8
near=2 far=4 huge=8
near=4 far=4 huge=8
Your Answer: Option
(Not Answered)
Correct Answer: Option
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()
{
    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;
}
JCK
J65K
JAK
JACK
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
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;
}
x=31, y=502, z=502
x=31, y=500, z=500
x=31, y=498, z=498
x=31, y=504, z=504
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the statements is correct about the program?
#include<stdio.h>

int main()
{
    int arr[3][3] = {1, 2, 3, 4};
    printf("%d\n", *(*(*(arr))));
    return 0;
}
Output: Garbage value
Output: 1
Output: 3
Error: Invalid indirection
Your Answer: Option
(Not Answered)
Correct Answer: Option

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;
}
BIX
India
India BIX
India\0BIX
Your Answer: Option
(Not Answered)
Correct Answer: Option
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;
}
Error: Invalid structure assignment
DRAVID
Dravid
No output
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Point out the error in the program?
#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
    char name[20];
    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;
}
Error: in structure
Error: in prototype declaration unknown struct emp
No error
None of above
Your Answer: Option
(Not Answered)
Correct Answer: Option
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.

12.
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;
}
Error: invalid structure member in printf
Error in this float category:5; statement
No error
None of above
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Bit field type must be signed int or unsigned int.

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


13.
The '.' operator can be used access structure elements using a structure variable.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Can we specify a variable filed width in a scanf() format string?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
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.

15.
Which header file should be included to use functions like malloc() and calloc()?
memory.h
stdlib.h
string.h
dos.h
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
If malloc() successfully allocates memory it returns the number of bytes it has allocated.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
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.

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.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
We can allocate a 2-Dimensional array dynamically.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Are the following declarations same?
char far *far *scr;
char far far** scr;
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
What is the purpose of fflush() function.
flushes all streams and specified streams.
flushes only specified stream.
flushes input/output buffer.
flushes file buffer.
Your Answer: Option
(Not Answered)
Correct Answer: Option
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.


*** END OF THE TEST ***
Time Left: 00:29:56
Post your test result / feedback here: