Online C Programming Test - C Programming Test 4



Loading...  Loading Test...

Instruction:

  • Total number of questions : 20.
  • Time alloted : 20 minutes.
  • Each question carry 1 mark, no negative marks.
  • DO NOT refresh the page.
  • All the best :-).

1.

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

2.

What will be the output of the program?

#include<stdio.h>
int main()
{
    int i=-3, j=2, k=0, m;
    m = ++i && ++j || ++k;
    printf("%d, %d, %d, %d\n", i, j, k, m);
    return 0;
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j || ++k;
becomes m = (-2 && 3) || ++k;
becomes m = TRUE || ++k;.
(++k) is not executed because (-2 && 3) alone return TRUE.
Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j are increemented by '1'(one).

Hence the output is "-2, 3, 0, 1".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

3.

What will be the output of the program?

#include<stdio.h>

int addmult(int ii, int jj)
{
    int kk, ll;
    kk = ii + jj;
    ll = ii * jj;
    return (kk, ll);
}

int main()
{
    int i=3, j=4, k, l;
    k = addmult(i, j);
    l = addmult(i, j);
    printf("%d, %d\n", k, l);
    return 0;
}

A.
12, 12
B.
7, 7
C.
7, 12
D.
12, 7

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: int i=3, j=4, k, l; The variables i, j, k, l are declared as an integer type and variable i, j are initialized to 3, 4 respectively.

The function addmult(i, j); accept 2 integer parameters.

Step 2: k = addmult(i, j); becomes k = addmult(3, 4)

In the function addmult(). The variable kk, ll are declared as an integer type int kk, ll;

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'.

ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'.

return (kk, ll); It returns the value of variable ll only.

The value 12 is stored in variable 'k'.

Step 3: l = addmult(i, j); becomes l = addmult(3, 4)

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'.

ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'.

return (kk, ll); It returns the value of variable ll only.

The value 12 is stored in variable 'l'.

Step 4: printf("%d, %d\n", k, l); It prints the value of k and l

Hence the output is "12, 12".

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

4.

Will the following program print the message infinite number of times?

#include<stdio.h>
#define INFINITELOOP while(1)

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

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Yes, the program prints "IndiaBIX" and runs infinitely.

The macro INFINITELOOP while(1) replaces the text 'INFINITELOOP' by 'while(1)'

In the main function, while(1) satisfies the while condition and it prints "IndiaBIX". Then it comes to while(1) and the loop runs infinitely.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

5.

What will be the output of the program ?

#include<stdio.h>
int *check(static int, static int);

int main()
{
    int *c;
    c = check(10, 20);
    printf("%d\n", c);
    return 0;
}
int *check(static int i, static int j)
{
    int *p, *q;
    p = &i;
    q = &j;
    if(i >= 45)
        return (p);
    else
        return (q);
}

A.
10
B.
20
C.
Error: Non portable pointer conversion
D.
Error: cannot use static for function parameters

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

6.

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

#include<stdio.h>

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}

A.
10, 2, 4
B.
20, 4, 4
C.
16, 2, 2
D.
20, 2, 2

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

7.

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 */
    }
}

A.
j=s;
B.
*j=s;
C.
*j=&s;
D.
&j=s;

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

8.

What will be the output of the program if the array begins at address 65486?

#include<stdio.h>

int main()
{
    int arr[] = {12, 14, 15, 23, 45};
    printf("%u, %u\n", arr, &arr);
    return 0;
}

A.
65486, 65488
B.
65486, 65486
C.
65486, 65490
D.
65486, 65487

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized.

Step 2: printf("%u, %u\n", arr, &arr); Here,

The base address of the array is 65486.

=> arr, &arr is pointing to the base address of the array arr.

Hence the output of the program is 65486, 65486

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

9.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    int i;
    char a[] = "\0";
    if(printf("%s", a))
        printf("The string is empty\n");
    else
        printf("The string is not empty\n");
    return 0;
}

A.
The string is empty
B.
The string is not empty
C.
No output
D.
0

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The function printf() returns the number of charecters printed on the console.

Step 1: char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty.

Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if condition is failed.

In the else part it prints "The string is not empty".

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

10.

What will be the output of the following program in 16 bit platform assuming that 1022 is memory address of the string "Hello1" (in Turbo C under DOS) ?

#include<stdio.h>

int main()
{
    printf("%u %s\n", &"Hello1", &"Hello2");
    return 0;
}

A.
1022 Hello2
B.
Hello1 1022
C.
Hello1 Hello2
D.
1022 1022
E.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

In printf("%u %s\n", &"Hello", &"Hello");.

The %u format specifier tells the compiler to print the memory address of the "Hello1".

The %s format specifier tells the compiler to print the string "Hello2".

Hence the output of the program is "1022 Hello2".

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

11.

If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?

struct ex
{
    char ch;
    int i;
    long int a;
};

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

A compiler may leave holes in structures by padding the first char in the structure with another byte just to ensures that the integer that follows is stored at an location. Also, there might be 2extra bytes after the integer to ensure that the long integer is stored at an address, which is multiple of 4. Such alignment is done by machines to improve the efficiency of accessing values.

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

12.

Point out the error/warning in the program?

#include<stdio.h>

int main()
{
    unsigned char ch;
    FILE *fp;
    fp=fopen("trial", "r");
    while((ch = getc(fp))!=EOF)
        printf("%c", ch);
    fclose(fp);
    return 0;
}

A.
Error: in unsigned char declaration
B.
Error: while statement
C.
No error
D.
It prints all characters in file "trial"

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Here, EOF is -1. As 'ch' is declared as unsigned char it cannot deal with any negative value.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

13.

What will be the output of the program

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

int main(int argc)
{
    printf("%d ", argc);
    fun(argc);
    return 0;
}
void fun(int i)
{
    if(i!=4)
        main(++i);
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

14.

Which of the following statements are correct about the program?

#include<stdio.h>

int main()
{
    unsigned int num;
    int i;
    scanf("%u", &num);
    for(i=0; i<16; i++)
    {
        printf("%d", (num<<i & 1<<15)?1:0);
    }
    return 0;
}

A.
It prints all even bits from num
B.
It prints all odd bits from num
C.
It prints binary equivalent num
D.
Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

If we give input 4, it will print 00000000 00000100 ;

If we give input 3, it will print 00000000 00000011 ;

If we give input 511, it will print 00000001 11111111 ;

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

15.

What will be the output of the program?

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

int main()
{
    int i=10;
    const int *ptr = &i;
    fun(&ptr);
    return 0;
}
int fun(int **ptr)
{
    int j = 223;
    int *temp = &j;
    printf("Before changing ptr = %5x\n", *ptr);
    const *ptr = temp;
    printf("After changing ptr = %5x\n", *ptr);
    return 0;
}

A.
Address of i
Address of j
B.
10
223
C.
Error: cannot convert parameter 1 from 'const int **' to 'int **'
D.
Garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

16.

Can I increase the size of dynamically allocated array?

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Use realloc(variable_name, value);

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

17.

It is necessary to call the macro va_end if va_start is called in the function.

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

18.

What do the following declaration signify?

void (*cmp)();

A.
cmp is a pointer to an void function type.
B.
cmp is a void type pointer function.
C.
cmp is a function that return a void pointer.
D.
cmp is a pointer to a function which returns void .

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

19.

What will be the output of the program (in Turbo C under DOS)?

#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, 8
B.
2, 4, 4
C.
4, 4, 2
D.
2, 4, 8

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

20.

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    char *i = "55.555";
    int result1 = 10;
    float result2 = 11.111;
    result1 = result1+atoi(i);
    result2 = result2+atof(i);
    printf("%d, %f", result1, result2);
    return 0;
}

A.
55, 55.555
B.
66, 66.666600
C.
65, 66.666000
D.
55, 55

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Function atoi() converts the string to integer.
Function atof() converts the string to float.

result1 = result1+atoi(i);
Here result1 = 10 + atoi(55.555);
result1 = 10 + 55;
result1 = 65;

result2 = result2+atof(i);
Here result2 = 11.111 + atof(55.555);
result2 = 11.111 + 55.555000;
result2 = 66.666000;
So the output is "65, 66.666000" .

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

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