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.
When we mention the prototype of a function?
Defining
Declaring
Prototyping
Calling
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type.

While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface.


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

3.
Is there any difference in the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Yes, we have to specify the data type of the parameter when declaring a function.

4.
How many times the while loop will get executed if a short int is 2 byte wide?
#include<stdio.h>
int main()
{
    int j=1;
    while(j <= 255)
    {
        printf("%c %d\n", j, j);
        j++;
    }
    return 0;
}
Infinite times
255 times
256 times
254 times
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.


5.
Which of the following statements are correct about an if-else statements in a C-program?
1: Every if-else statement can be replaced by an equivalent statements using   ?: operators
2: Nested if-else statements are allowed.
3: Multiple statements in an if block are allowed.
4: Multiple statements in an else block are allowed.
1 and 2
2 and 3
1, 2 and 4
2, 3, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statements are correct about the below C-program?
#include<stdio.h>
int main()
{
    int x = 10, y = 100%90, i;
    for(i=1; i<10; i++)
    if(x != y);
        printf("x = %d y = %d\n", x, y);
    return 0;
}
1 : The printf() function is called 10 times.
2 : The program will produce the output x = 10 y = 10
3 : The ; after the if(x!=y) will NOT produce an error.
4 : The program will not produce output.
1
2, 3
3, 4
4
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Associativity of an operator is either Left to Right or Right to Left.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Yes, the associativity of an operator is either Left to Right or Right to Left.


8.
What are the different types of real data type in C ?
float, double
short int, double, long int
float, double, long double
double, long int, float
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
The floating point data types are called real data types. Hence float, double, and long double are real data types.

9.
What will be the output of the program?
#include<stdio.h>
#define MAX(a, b) (a > b ? a : b)

int main()
{
    int x;
    x = MAX(3+2, 2+7);
    printf("%d\n", x);
    return 0;
}
8
9
6
5
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.

Step 1 : int x; The variable x is declared as an integer type.

Step 2 : x = MAX(3+2, 2+7); becomes,

=> x = (3+2 > 2+7 ? 3+2 : 2+7)

=> x = (5 > 9 ? 5 : 9)

=> x = 9

Step 3 : printf("%d\n", x); It prints the value of variable x.

Hence the output of the program is 9.


10.
What will be the output of the program?
#include<stdio.h>
#define CUBE(x) (x*x*x)

int main()
{
    int a, b=3;
    a = CUBE(b++);
    printf("%d, %d\n", a, b);
    return 0;
}
9, 4
27, 4
27, 6
Error
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

The macro function CUBE(x) (x*x*x) calculates the cubic value of given number(Eg: 103.)

Step 1: int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.

Step 2: a = CUBE(b++); becomes

=> a = b++ * b++ * b++;

=> a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not incremented in this statement.

=> a = 27; Here, 27 is store in the variable a. By the way, the value of variable b is incremented by 3. (ie: b=6)

Step 3: printf("%d, %d\n", a, b); It prints the value of variable a and b.

Hence the output of the program is 27, 6.


11.
Macros with arguments are allowed
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

True, A macro may have arguments.

Example: #define CUBE(X)(X*X*X)


12.
Will it result in to an error if a header file is included twice?
Yes
No
It is compiler dependent.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Unless the header file has taken care to ensure that if already included it doesn't get included again.

Turbo C, GCC compilers would take care of these problems, generate no error.

13.
A pointer union CANNOT be created
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
cmd> sample Good Morning
/* sample.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    printf("%d %s", argc, argv[1]);
    return 0;
}
3 Good
2 Good
Good Morning
3 Morning
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Even if integer/float arguments are supplied at command prompt they are treated as strings.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

int main()
{
    typedef float f;
    static f *fptr;
    float fval = 90;
    fptr = &fval;
    printf("%f\n", *fptr);
    return 0;
}
9
0
90.000000
90
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Assume integer is 2 bytes wide. What will be the output of the following code?
#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4

int main()
{
    int (*p)[MAXCOL];
    p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p));
    printf("%d, %d\n", sizeof(p), sizeof(*p));
    return 0;
}
2, 8
4, 16
8, 24
16, 32
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Can the fixed arguments passed to the function that accepts variable argument list, occur at the end?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Function can return a floating point number.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
What will the function rewind() do?
Reposition the file pointer to a character reverse.
Reposition the file pointer stream to end of file.
Reposition the file pointer to begining of that line.
Reposition the file pointer to begining of file.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
rewind() takes the file pointer to the beginning of the file. so that the next I/O operation will take place at the beginning of the file.
Example: rewind(FilePointer);

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