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.

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

2.

What will be the output of the program?

#include<stdio.h>
int main()
{
    int x, y, z;
    x=y=z=1;
    z = ++x || ++y && ++z;
    printf("x=%d, y=%d, z=%d\n", x, y, z);
    return 0;
}

A.
x=2, y=1, z=1
B.
x=2, y=2, z=1
C.
x=2, y=2, z=2
D.
x=1, y=2, z=1

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: x=y=z=1; here the variables x ,y, z are initialized to value '1'.

Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x becomes 2. So there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns '1'. So the value of variable z is '1'

Step 3: printf("x=%d, y=%d, z=%d\n", x, y, z); It prints "x=2, y=1, z=1". here x is increemented in previous step. y and z are not increemented.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

3.

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

#include<stdio.h>

int main()
{
    struct emp
    {
        char *n;
        int age;
    };
    struct emp e1 = {"Dravid", 23};
    struct emp e2 = e1;
    strupr(e2.n);
    printf("%s\n", e1.n);
    return 0;
}

A.
Error: Invalid structure assignment
B.
DRAVID
C.
Dravid
D.
No output

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum

4.

Bitwise & can be used to check if more than one bit in a number is on.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

5.

In the statement expression1 >> expression2. if expression1 is a signed integer with its leftmost bit set to 1 then on right shifting it the result of the statement will vary from computer to computer

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

6.

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

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

int main(int sizeofargv, char *argv[])
{
    while(sizeofargv)
        printf("%s", argv[--sizeofargv]);
    return 0;
}

A.
sample friday tuesday sunday
B.
sample friday tuesday
C.
sunday tuesday friday sample
D.
sunday tuesday friday

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum

7.

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

A.
9
B.
0
C.
90.000000
D.
90

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

8.

Will the program compile?

#include<stdio.h>
int main()
{
    char str[5] = "IndiaBIX";
    return 0;
}

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

C doesn't do array bounds checking at compile time, hence this compiles.

But, the modern compilers like Turbo C++ detects this as 'Error: Too many initializers'.

GCC would give you a warning.

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

9.

What is (void*)0?

A.
Representation of NULL pointer
B.
Representation of void pointer
C.
Error
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

10.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main()
{
    int n = 0, y = 1;
    y == 1 ? n=0 : n=1;
    if(n)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

A.
Error: Declaration terminated incorrectly
B.
Error: Syntax error
C.
Error: Lvalue required
D.
None of above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

11.

Which of the following statements are correct about the program?

#include<stdio.h>
int main()
{
    int x = 30, y = 40;
    if(x == y)
        printf("x is equal to y\n");

    else if(x > y)
        printf("x is greater than y\n");

    else if(x < y)
        printf("x is less than y\n")
    return 0;
}

A.
Error: Statement missing
B.
Error: Expression syntax
C.
Error: Lvalue required
D.
Error: Rvalue required

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

This program will result in error "Statement missing ;"

printf("x is less than y\n") here ; should be added to the end of this statement.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

12.

What will be the output of the program?

#include<stdio.h>

int main()
{
    const int x=5;
    const int *ptrx;
    ptrx = &x;
    *ptrx = 10;
    printf("%d\n", x);
    return 0;
}

A.
5
B.
10
C.
Error
D.
Garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Step 1: const int x=5; The constant variable x is declared as an integer data type and initialized with value '5'.

Step 2: const int *ptrx; The constant variable ptrx is declared as an integer pointer.

Step 3: ptrx = &x; The address of the constant variable x is assigned to integer pointer variable ptrx.

Step 4: *ptrx = 10; Here we are indirectly trying to change the value of the constant vaiable x. This will result in an error.

To change the value of const variable x we have to use *(int *)&x = 10;

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

13.

What will be the output of the program?

#include<stdio.h>

int main()
{
    const c = -11;
    const int d = 34;
    printf("%d, %d\n", c, d);
    return 0;
}

A.
Error
B.
-11, 34
C.
11, 34
D.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Step 1: const c = -11; The constant variable 'c' is declared and initialized to value "-11".

Step 2: const int d = 34; The constant variable 'd' is declared as an integer and initialized to value '34'.

Step 3: printf("%d, %d\n", c, d); The value of the variable 'c' and 'd' are printed.

Hence the output of the program is -11, 34

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

14.

Point out the error in the following program.

#include<stdio.h>

int main()
{
    char str[] = "IndiaBIX";
    printf("%.#s %2s", str, str);
    return 0;
}

A.
Error: in Array declaration
B.
Error: printf statement
C.
Error: unspecified character in printf
D.
No error

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

15.

Which of the following are correct preprocessor directives in C?
1: #ifdef
2: #if
3: #elif
4: #undef

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The macros #ifdef #if #elif are called conditional macros.

The macro #undef undefine the previosly declared macro symbol.

Hence all the given statements are macro preprocessor directives.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

16.

stderr, stdin, stdout are FILE pointers

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Yes, these will be declared like

The corresponding stdio.h variable is FILE* stdin;

The corresponding stdio.h variable is FILE* stdout;

The corresponding stdio.h variable is FILE* stderr;

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum

17.

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char str[25] = "IndiaBIX";
    printf("%s\n", &str+2);
    return 0;
}

A.
Garbage value
B.
Error
C.
No output
D.
diaBIX

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: char str[25] = "IndiaBIX"; The variable str is declared as an array of characteres and initialized with a string "IndiaBIX".

Step 2: printf("%s\n", &str+2);

=> In the printf statement %s is string format specifier tells the compiler to print the string in the memory of &str+2

=> &str is a location of string "IndiaBIX". Therefore &str+2 is another memory location.

Hence it prints the Garbage value.

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

18.

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

A.
1
B.
2
C.
3
D.
All of above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

In 2 and 3 semicolon are missing in structure element.

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

19.

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

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

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

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

20.

Every operator has an Associativity

A.
Yes
B.
No

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Yes, Each and every operator has an associativity.

The associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. Operators may be left-associative, right-associative or non-associative.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

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


Have a question?

Ask your question now !

Create your own website ?

Web Hosting Services in India