AmbitionBox

Discover Best Places to work in India

C Programming

C Programming Questions and Answers

Showing 1 - 9 of 9 questions

1

What will be output of the following?

 

#include<stdio.h>int main()
{
    float a=0.7;
    if(a < 0.7)
        printf("Cn");
    else
        printf("C++n");
    return0;
}
a

C

b

C++

c

Error

d

None of these

correct answer a

Answer : Option A

Explanation :

 if(a < 0.7) here a is a float variable and 0.7 is a double constant. The float variable a is less than double constant 0.7. Hence the if condition is satisfied and it prints 'C'

 

#include<stdio.h>int main()
{
    float a=0.7;
    printf("%.10f %.10fn",0.7, a);
    return0;
}

Output:
0.7000000000 0.6999999881

2

A float occupies 4 bytes. if the hexadecimal equivalent of each of these bytes is A,B,C and D, then when this float is stored in memory, these bytes get stored in the order

a

ABCD

b

DCBA

c

0xABCD

d

0xDCBA

correct answer b

Answer : Option B

3

We want to round off x, a float to an int value. The correct way to do so would be

a

y=(int)(x+0.5)

b

y=int(x+0.5)

c

y=(int)x+0.5

d

y=(int)(x+0.5)

correct answer a

Answer : Option A

4

What will be output of the program ?

 

#include<stdio.h>#include<math.h>int main()
{
    printf("%d, %d, %dn", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));
    return0;
}
a

4, 4, 4

b

4, 8, 8

c

4, 8, 10

d

4, 8, 12

correct answer c

Answer : Option C

Explanation :
 
sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.

sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.

sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.

Note: If you run the above program in Linux platform (GCC Compiler) it will give 4, 8, 12 as output. If you run in Windows platform (TurboC Compiler) it will give 4, 8, 10 as output. Because, C is a machine dependent language.

5

By default any real number is treated as :

a

a float

b

a double

c

a long double

d

depends on the memory model that you are using

correct answer b

Answer : Option B

6

What will be output of the following ?

 

#include<stdio.h>#include<math.h>int main()
{
    printf("%fn", sqrt(36.0));
    return0;
}
a

6.0

b

6

c

6.0000

d

Some absurd result

correct answer c

Answer : Option C

Explanation :

printf("%fn", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).

Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the given number.

7

Binary equivalent of 5.375 is

a

101.101110111

b

101.011

c

101011

d

none of these

correct answer b

Answer : Option B

8

Which error you are likely to get when you run the following program?

    #include<stdio.h>
    main()
    {
       struct emp
       {
         char name[20];
         float sal;
       }
       struct emp e[10];
       int i;
       for(i=0;i<=9;i++)
       scanf("%s, %f",e[i].name,&e[i].sal);
       return 0;
    }

a

suspecious pointer conversion

b

Floating point formats not linked

c

Cannot use scanf for strutures

d

Strings cannot be nested inside structures

correct answer b

Answer : Option B

9

If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program?

    #include<stdio.h>
    int main()
    {
        float a =5.375;
        char *p;
        int i;
        p = (char*)&a;
        for(i=0;i<=3;i++)
             printf("%02x", (unsigned char)p[i]);
        return 0;
    }

a

40 AC 00 00

b

04 CA 00 00

c

00 00 AC 40

d

00 00 CA 04

correct answer c

Answer : Option C

Select a company to compare with

vs

Similar Companies