Online C Programming Test - C Programming Test - Random

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: 30 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.
Identify which of the following are declarations
1 : extern int x;
2 : float square ( float x ) { ... }
3 : double pow(double, double);
1
2
1 and 3
3
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
extern int x; - is an external variable declaration.

double pow(double, double); - is a function prototype declaration.

Therefore, 1 and 3 are declarations. 2 is definition.

2.
Which of the structure is incorrcet?
1 :
struct aa
{
    int a;
    float b;
};
2 :
struct aa
{
    int a;
    float b;
    struct aa var;
};
3 :
struct aa
{
    int a;
    float b;
    struct aa *var;
};
1
2
3
1, 2, 3
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Option B gives "Undefined structure in 'aa'" error.


3.
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
    int i = 1;
    switch(i)
    {
        case 1:
           printf("Case1");
           break;
        case 1*2+4:
           printf("Case2");
           break;
    }
return 0;
}
Error: in case 1*2+4 statement
Error: No default specified
Error: in switch statement
No Error
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Constant expression are accepted in switch

It prints "Case1"


4.
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.


5.
What will be the output of the program?
#include<stdio.h>
int main()
{
    float f=43.20;
    printf("%e, ", f);
    printf("%f, ", f);
    printf("%g", f);
    return 0;
}
4.320000e+01, 43.200001, 43.2
4.3, 43.22, 43.21
4.3e, 43.20f, 43.00
Error
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

printf("%e, ", f); Here '%e' specifies the "Scientific Notation" format. So, it prints the 43.20 as 4.320000e+01.

printf("%f, ", f); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the 43.20 as 43.200001.

printf("%g, ", f); Here '%g' "Use the shorter of %e or %f". So, it prints the 43.20 as 43.2.


6.
What will be the output of the program?
#include<stdio.h>
int main()
{
    float a=0.7;
    if(a < 0.7f)
        printf("C\n");
    else
        printf("C++\n");
    return 0;
}
C
C++
Compiler error
Non of above
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

if(a < 0.7f) here a is a float variable and 0.7f is a float constant. The float variable a is not less than 0.7f float constant. But both are equal. Hence the if condition is failed and it goes to else it prints 'C++'
Example:

#include<stdio.h>
int main()
{
    float a=0.7;
    printf("%.10f %.10f\n",0.7f, a);
    return 0;
}

Output:
0.6999999881 0.6999999881


7.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i=0;
    i++;
    if(i<=5)
    {
        printf("IndiaBIX");
        exit(1);
        main();
    }
    return 0;
}
Prints "IndiaBIX" 5 times
Function main() doesn't calls itself
Infinite loop
Prints "IndiaBIx"
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero).

Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one).

Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements.

Step 4: printf("IndiaBIX"); It prints "IndiaBIX".

Step 5: exit(1); This exit statement terminates the program execution.

Hence the output is "IndiaBIx".


8.
What will be the output of the program in 16 bit platform (Turbo C under DOS)?
#include<stdio.h>

int main()
{
    int fun();
    int i;
    i = fun();
    printf("%d\n", i);
    return 0;
}
int fun()
{
    _AX = 1990;
}
Garbage value
0 (Zero)
1990
No output
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Turbo C (Windows): The return value of the function is taken from the Accumulator _AX=1990.

But it may not work as expected in GCC compiler (Linux).


9.
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);
    }
}
0, 2, 1, 0,
1, 1, 2, 0,
0, 1, 0, 2,
0, 1, 2, 0,
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
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.

11.
In the following program add a statement in the function fact() such that the factorial gets stored in j.
#include<stdio.h>
void fact(int*);

int main()
{
    int i=5;
    fact(&i);
    printf("%d\n", i);
    return 0;
}
void fact(int *j)
{
    static int s=1;
    if(*j!=0)
    {
        s = s**j;
        *j = *j-1;
        fact(j);
        /* Add a statement here */
    }
}
j=s;
*j=s;
*j=&s;
&j=s;
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Are the expressions arr and &arr same for an array of 10 integers?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints.

13.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    static char mess[6][30] = {"Don't walk in front of me...", 
                               "I may not follow;", 
                               "Don't walk behind me...", 
                               "Just walk beside me...", 
                               "And be my friend." };

    printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));
    return 0;
}
t, t
k, k
n, k
m, f
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf(5+"Good Morning\n");
    return 0;
}
Good Morning
Good
M
Morning
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.

Hence the output is "Morning"


15.
The maximum combined length of the command-line arguments including the spaces between adjacent arguments is
128 characters
256 characters
67 characters
It may vary from one operating system to another
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Specify the 2 library functions to dynamically allocate memory?
malloc() and memalloc()
alloc() and memalloc()
malloc() and calloc()
memalloc() and faralloc()
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
What will be the output of the program?
#include<stdio.h>
#include<stdarg.h>
void fun1(int num, ...);
void fun2(int num, ...);

int main()
{
    fun1(1, "Apple", "Boys", "Cats", "Dogs");
    fun2(2, 12, 13, 14);
    return 0;
}
void fun1(int num, ...)
{
    char *str;
    va_list ptr;
    va_start(ptr, num);
    str = va_arg(ptr, char *);
    printf("%s ", str);
}
void fun2(int num, ...)
{
    va_list ptr;
    va_start(ptr, num);
    num = va_arg(ptr, int);
    printf("%d", num);
}
Dogs 12
Cats 14
Boys 13
Apple 12
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
fun(...);

int main()
{
    fun(3, 7, -11.2, 0.66);
    return 0;
}
fun(...)
{
    va_list ptr;
    int num;
    va_start(ptr, n);
    num = va_arg(ptr, int);
    printf("%d", num);
}
Error: fun() needs return type
Error: ptr Lvalue required
Error: Invalid declaration of fun(...)
No error
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
There is no fixed argument in the definition fun()

19.
What do the following declaration signify?
char *scr;
scr is a pointer to pointer variable.
scr is a function pointer.
scr is a pointer to char.
scr is a member of function pointer.
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
What will be the output of the program in DOS (Compiler - Turbo C)?
#include<stdio.h>
double i;

int main()
{
    (int)(float)(char) i;
    printf("%d",sizeof(i));
    return 0;
}
4
8
16
22
Your Answer: Option
(Not Answered)
Correct Answer: Option

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