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.
Which of the structure is correct?
1 :
struct book
{
    char name[10];
    float price;
    int pages;
};
2 :
struct aa
{
    char name[10];
    float price;
    int pages;
}
3 :
struct aa
{
    char name[10];
    float price;
    int pages;
}
1
2
3
All of above
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
In 2 and 3 semicolon are missing in structure element.

2.
Which of the following correctly represents a long double constant?
6.68
6.68L
6.68f
6.68LF
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

6.68 is double.
6.68L is long double constant.
6.68f is float constant.
6.68LF is not allowed in c.


3.
Which of the following is not logical operator?
&
&&
||
!
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

Bitwise operators:
& is a Bitwise AND operator.

Logical operators:
&& is a Logical AND operator.
|| is a Logical OR operator.
! is a NOT operator.

So, '&' is not a Logical operator.


4.
A function cannot be defined inside another function
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

A function cannot be defined inside the another function, but a function can be called inside a another function.


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


6.
What will be the output of the program?
#include<stdio.h>
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
int main()
{
    char *str1="India";
    char *str2="BIX";
    JOIN(str1, str2);
    return 0;
}
str1=IndiaBIX str2=BIX
str1=India str2=BIX
str1=India str2=IndiaBIX
Error: in macro substitution
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
A preprocessor directive is a message from compiler to a linker.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

FALSE

Example: #define symbol replacement

When the preprocessor encounters #define directive, it replaces any occurrence of symbol in the rest of the code by replacement. This replacement can be an statement or expression or a block or simple text.


8.
What will be the output of the program ?
#include<stdio.h>
power(int**);
int main()
{
    int a=5, *aa; /* Address of 'a' is 1000 */
    aa = &a;
    a = power(&aa);
    printf("%d\n", a);
    return 0;
}
power(int **ptr)
{
    int b;
    b = **ptr***ptr;
    return (b);
}
5
25
125
Garbage value
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements correctly declare a function that receives a pointer to pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float?
float **fun(float***);
float *fun(float**);
float fun(float***);
float ****fun(float***);
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

int main()
{
    char str[] = "India\0\BIX\0";
    printf("%d\n", strlen(str));
    return 0;
}
10
6
5
11
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

The function strlen returns the number of characters int the given string.

Therefore, strlen(str) becomes strlen("India") contains 5 characters. A string is a collection of characters terminated by '\0'.

The output of the program is "5".


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;
}
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.


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

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

int main()
{
    int a=250;
    printf("%1d\n", a);
    return 0;
}
1250
2
50
250
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

int a=250; The variable a is declared as an integer type and initialized to value 250.

printf("%1d\n", a); It prints the value of variable a.

Hence the output of the program is 250.


14.
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;
}
Error: unrecognised Keyword SEEK_SET
Error: fseek() long offset value
No error
None of above
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Instead of "20" use 20L since fseek() need a long offset value.

15.
Which of the following statement is correct about the program?
#include<stdio.h>

int main()
{
    FILE *fp;
    char ch;
    int i=1;
    fp = fopen("myfile.c", "r");
    while((ch=getc(fp))!=EOF)
    {
        if(ch == '\n')
            i++;
    }
    fclose(fp);
    return 0;
}
The code counts number of characters in the file
The code counts number of words in the file
The code counts number of blank lines in the file
The code counts number of lines in the file
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:

This program counts the number of lines in the file myfile.c by counting the character '\n' in that file.


16.
Does there exist any way to make the command-line arguments available to other functions without passing them as arguments to the function?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Using the predefined variables _argc, _argv. This is a compiler dependent feature. It works in TC/TC++ but not in gcc and visual studio.

17.
Bitwise & can be used to check if a bit in number is set or not.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
A function that receives variable number of arguments should use va_arg() to extract arguments from the variable argument list.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
The macro va_arg is used to extract an argument from the variable argument list and advance the pointer to the next argument.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Can we pass a variable argument list to a function at run-time?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Every actual argument list must be known at compile time. In that sense it is not truly a variable argument list.

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