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.

Declare the following statement?
"A pointer to a function which receives nothing and returns nothing".

A.
void *(ptr)*int;
B.
void *(*ptr)()
C.
void *(*ptr)(*)
D.
void (*ptr)()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

2.

What will be the output of the program If the integer is 4bytes long?

#include<stdio.h>

int main()
{
    int ***r, **q, *p, i=8;
    p = &i;
    q = &p;
    r = &q;
    printf("%d, %d, %d\n", *p, **q, ***r);
    return 0;
}

A.
8, 8, 8
B.
4000, 4002, 4004
C.
4000, 4004, 4008
D.
4000, 4008, 4016

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

3.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char *str;
    str = "%s";
    printf(str, "K\n");
    return 0;
}

A.
Error
B.
No output
C.
K
D.
%s

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

4.

Which of the following statements correct about the below program?

#include<stdio.h>

int main()
{
    struct emp
    {
        char name[25];
        int age;
        float sal;
    };
    struct emp e[2];
    int i=0;
    for(i=0; i<2; i++)
        scanf("%s %d %f", e[i].name, &e[i].age, &e[i].sal);

    for(i=0; i<2; i++)
        scanf("%s %d %f", e[i].name, e[i].age, e[i].sal);
    return 0;
}

A.
Error: scanf() function cannot be used for structures elements.
B.
The code runs successfully.
C.
Error: Floating point formats not linked Abnormal program termination.
D.
Error: structure variable must be initialized.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

5.

The prototypes of all standard library string functions are declared in the file string.h.

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

string.h is the header in the C standard library for the C programming language which contains macro definitions, constants, and declarations of functions and types used not only for string handling but also various memory handling functions.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

6.

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?

A.
rem = (5.5 % 1.3)
B.
rem = modf(5.5, 1.3)
C.
rem = fmod(5.5, 1.3)
D.
Error: we can't divide

Your Answer: Option (Not Answered)

Correct Answer: Option C

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

Example:


#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
  return 0;
}

Output:
fmod of 5.5 by 1.3 is 0.300000

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum

7.

Point out the error in the program.

#include<stdio.h>

int main()
{
    const int k=7;
    int *const q=&k;
    printf("%d", *q);
    return 0;
}

A.
Error: RValue required
B.
Error: Lvalue required
C.
Error: cannot convert from 'const int *' to 'int *const'
D.
No error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

No error. This will produce 7 as output.

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

8.

What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample "*.c"

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

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

A.
*.c
B.
"*.c"
C.
sample *.c
D.
List of all files and folders in the current directory

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

9.

Point out the error in the program?

struct emp
{
    int ecode;
    struct emp *e;
};

A.
Error: in structure declaration
B.
Linker Error
C.
No Error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

This type of declaration is called as self-referential structure. Here *e is pointer to a struct emp.

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

10.

The library function used to find the last occurrence of a character in a string is

A.
strnstr()
B.
laststr()
C.
strrchr()
D.
strstr()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Declaration: char *strrchr(const char *s, int c);

It scans a string s in the reverse direction, looking for a specific character c.

Example:

#include <string.h>
#include <stdio.h>

int main(void)
{
   char text[] = "I learn through IndiaBIX.com";
   char *ptr, c = 'i';

   ptr = strrchr(text, c);
   if (ptr)
      printf("The position of '%c' is: %d\n", c, ptr-text);
   else
      printf("The character was not found\n");
   return 0;
}

Output:

The position of 'i' is: 19

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

11.

What will be the output of the program?

#include<stdio.h>
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)

int main()
{
    int x;
    x = MAX(3+2, 2+7, 3+7);
    printf("%d\n", x);
    return 0;
}

A.
5
B.
9
C.
10
D.
3+7

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

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

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

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

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

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

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

=> x = 10

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

Hence the output of the program is "10".

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

12.

Which of the following statements are correct about the program?

#include<stdio.h>

int main()
{
    printf("%p\n", main());
    return 0;
}

A.
It prints garbage values infinitely
B.
Runs infinitely without printing anything
C.
Error: main() cannot be called inside printf()
D.
No Error and print nothing

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

13.

What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
    static char str1[] = "dills";
    static char str2[20];
    static char str3[] = "Daffo";
    int i;
    i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
    printf("%d\n", i);
    return 0;
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

14.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    printf(5+"Good Morning\n");
    return 0;
}

A.
Good Morning
B.
Good
C.
M
D.
Morning

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

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

Hence the output is "Morning"

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

15.

A float is 4 bytes wide, whereas a double is 8 bytes wide.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

True,
float = 4 bytes.
double = 8 bytes.

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

16.

Range of double is -1.7e-38 to 1.7e+38 (in 16 bit platform - Turbo C under DOS)

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

False, The range of double is -1.7e+308 to 1.7e+308.

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

17.

Size of short integer and long integer would vary from one platform to another.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

True, Depending on the operating system/compiler/system architecture you are working on, the range of data types can vary.

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

18.

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

19.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    void fun(int, int[]);
    int arr[] = {1, 2, 3, 4};
    int i;
    fun(4, arr);
    for(i=0; i<4; i++)
        printf("%d,", arr[i]);
    return 0;
}
void fun(int n, int arr[])
{
    int *p=0;
    int i=0;
    while(i++ < n)
        p = &arr[i];
    *p=0;
}

A.
2, 3, 4, 5
B.
1, 2, 3, 4
C.
0, 1, 2, 3
D.
3, 2, 1 0

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Step 1: void fun(int, int[]); This prototype tells the compiler that the function fun() accepts one integer value and one array as an arguments and does not return anything.

Step 2: int arr[] = {1, 2, 3, 4}; The variable a is declared as an integer array and it is initialized to

a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4

Step 3: int i; The variable i is declared as an integer type.

Step 4: fun(4, arr); This function does not affect the output of the program. Let's skip this function.

Step 5: for(i=0; i<4; i++) { printf("%d,", arr[i]); } The for loop runs untill the variable i is less than '4' and it prints the each value of array a.

Hence the output of the program is 1,2,3,4

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

20.

What will be the output of the program in TurboC?

#include<stdio.h>
int fun(int **ptr);

int main()
{
    int i=10, j=20;
    const int *ptr = &i;
    printf(" i = %5X", ptr);
    printf(" ptr = %d", *ptr);
    ptr = &j;
    printf(" j = %5X", ptr);
    printf(" ptr = %d", *ptr);
    return 0;
}

A.
i= FFE2 ptr=12 j=FFE4 ptr=24
B.
i= FFE4 ptr=10 j=FFE2 ptr=20
C.
i= FFE0 ptr=20 j=FFE1 ptr=30
D.
Garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

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