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.

ftell() returns the current position of the pointer in a file stream.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.

Example:


#include <stdio.h>

int main(void)
{
	FILE *stream;
	stream = fopen("MYFILE.TXT", "w+");
	fprintf(stream, "This is a test");
    printf("The file pointer is at byte %ld\n", ftell(stream));
    fclose(stream);
    return 0;
}

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum


2.

A short integer is at least 16 bits wide and a long integer is at least 32 bits wide.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The basic C compiler is 16 bit compiler, below are the size of it's data types
The size of short int is 2 bytes wide(16 bits).
The size of long int is 4 bytes wide(32 bits).

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


3.

How many times "IndiaBIX" is get printed?

#include<stdio.h>
int main()
{
    int x;
    for(x=-1; x<=10; x++)
    {
        if(x < 5)
            continue;
        else
            break;
        printf("IndiaBIX");
    }
    return 0;
}

A.
Infinite times
B.
11 times
C.
0 times
D.
10 times

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


4.

To print out a and b given below, which of the following printf() statement will you use?

#include<stdio.h>

float a=3.14;
double b=3.14;

A.
printf("%f %lf", a, b);
B.
printf("%Lf %f", a, b);
C.
printf("%Lf %Lf", a, b);
D.
printf("%f %Lf", a, b);

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

To print a float value, %f is used as format specifier.

To print a double value, %lf is used as format specifier.

Therefore, the answer is printf("%f %lf", a, b);

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum


5.

Point out the error in the program?

#include<stdio.h>

int main()
{
    FILE *fp;
    fp=fopen("trial", "r");
    fseek(fp, "20", SEEK_SET);
    fclose(fp);
    return 0;
}

A.
Error: unrecognised Keyword SEEK_SET
B.
Error: fseek() long offset value
C.
No error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Instead of "20" use 20L since fseek() need a long offset value.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum


6.

Can you combine the following two statements into one?

char *p;
p = (char*) malloc(100);

A.
char p = *malloc(100);
B.
char *p = (char) malloc(100);
C.
char *p = (char*)malloc(100);
D.
char *p = (char *)(malloc*)(100);

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum


7.

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

A.
True
B.
False

Your Answer: Option (Not Answered)

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

Discuss about this problem : Discuss in Forum


8.

What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog 1 2 3

/* myprog.c */
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char **argv)
{
    int i, j=0;
    for(i=0; i<argc; i++)
        j = j+atoi(argv[i]);
    printf("%d\n", j);
    return 0;
}

A.
123
B.
6
C.
Error
D.
"123"

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Command Line Arguments

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 (Turbo C in DOS)?
cmd> sample 1 2 3

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

int main(int argc, char *argv[])
{
    int j;
    j = argv[1] + argv[2] + argv[3];
    printf("%d", j);
    return 0;
}

A.
6
B.
sample 6
C.
Error
D.
Garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Here argv[1], argv[2] and argv[3] are string type. We have to convert the string to integer type before perform arithmetic operation.

Example: j = atoi(argv[1]) + atoi(argv[2]) + atoi(argv[3]);

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum


10.

How many times the program will print "IndiaBIX" ?

#include<stdio.h>

int main()
{
    printf("IndiaBIX");
    main();
    return 0;
}

A.
Infinite times
B.
32767 times
C.
65535 times
D.
Till stack overflows

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

A call stack or function stack is used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing.

A stack overflow occurs when too much memory is used on the call stack.

Here function main() is called repeatedly and its return address is stored in the stack. After stack memory is full. It shows stack overflow error.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


11.

Is the NULL pointer same as an uninitialised pointer?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum


12.

A macro must always be defined in capital letters.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

FALSE, The macro is case insensitive.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum


13.

What will be the output of the program?

#include<stdio.h>
void fun(int*, int*);
int main()
{
    int i=5, j=2;
    fun(&i, &j);
    printf("%d, %d", i, j);
    return 0;
}
void fun(int *i, int *j)
{
    *i = *i**i;
    *j = *j**j;
}

A.
5, 2
B.
10, 4
C.
2, 5
D.
25, 4

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Step 1: int i=5, j=2; Here variable i and j are declared as an integer type and initialized to 5 and 2 respectively.

Step 2: fun(&i, &j); Here the function fun() is called with two parameters &i and &j (The & denotes call by reference. So the address of the variable i and j are passed. )

Step 3: void fun(int *i, int *j) This function is called by reference, so we have to use * before the parameters.

Step 4: *i = *i**i; Here *i denotes the value of the variable i. We are multiplying 5*5 and storing the result 25 in same variable i.

Step 5: *j = *j**j; Here *j denotes the value of the variable j. We are multiplying 2*2 and storing the result 4 in same variable j.

Step 6: Then the function void fun(int *i, int *j) return back the control back to main() function.

Step 7: printf("%d, %d", i, j); It prints the value of variable i and j.

Hence the output is 25, 4.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


14.

What will be the output of the program?

#include<stdio.h>
void fun(int);
typedef int (*pf) (int, int);
int proc(pf, int, int);

int main()
{
    int a=3;
    fun(a);
    return 0;
}
void fun(int n)
{
    if(n > 0)
    {
        fun(--n);
        printf("%d,", n);
        fun(--n);
    }
}

A.
0, 2, 1, 0,
B.
1, 1, 2, 0,
C.
0, 1, 0, 2,
D.
0, 1, 2, 0,

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


15.

Names of functions in two different files linked together must be unique

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

True, If two function are declared in a same name, it gives "Error: Multiple declaration of function_name())".

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


16.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    int i=4, j=8;
    printf("%d, %d, %d\n", i|j&j|i, i|j&&j|i, i^j);
    return 0;
}

A.
4, 8, 0
B.
1, 2, 1
C.
12, 1, 12
D.
0, 0, 0

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum


17.

What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

A.
The element will be set to 0.
B.
The compiler would report an error.
C.
The program may crash if some important data gets overwritten.
D.
The array size would appropriately grow.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct answer. But the modern compilers will take care of this kind of errors.

Example: Run the below program, it will crash in Windows (TurboC Compiler)

#include<stdio.h>

int main()
{
    int arr[2];
    arr[3]=10;
    printf("%d",arr[3]);
    return 0;
}

Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the Turbo-C Compiler (Windows) output.

Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum


18.

Point out the error in the program in 16-bit platform?

#include<stdio.h>

int main()
{
    struct bits
    {
        int i:40;
    }bit;

    printf("%d\n", sizeof(bit));
    return 0;
}

A.
4
B.
2
C.
Error: Bit field too large
D.
Error: Invalid member access in structure

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum


19.

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


20.

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


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