Search Placementyogi.com
 

Objective Questions in C with Answers Page 2

  :: Topics ::

6

What will the statement

char ch='A';

 store in variable ch?

A.

The character A

B.

Ascii value of character A

C.

A along with inverted commas

D.

None of the above

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

The ascii value of a character constant is stored in a character variable, hence character variable is also sometimes called as a variation of int datatype.

 
7

What is the output of the following program?

#include <stdio.h>
int main(){
        int c=08;
        printf("%d",c);
        return 0;
}
A.

8

B.

0

C.

Compile Time Error

D.

None of the Above

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

Any number starting with 0 is treated as an octal value.

Here, 08 is an invalid octal value and hence the compiler throws the following error:

myprog.c:3:8: error: invalid digit "8" in octal constant

 
 
8

What is the output of the following program?

#include<stdio.h>
void main()
	{
		printf("%d",sizeof(5.2));
	}
A.

Compiler Error: Can't determine size of a constant

B.

4 (Size of float)

C.

8 (Size of double)

D.

Garbage Value

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

The default type for decimal constants is double and not float.

Hence the value 5.2 is treated as a double and 8 is printed.

 
9

What is the output of the following program?

#include<stdio.h>
int main(){
    double d=5.2;
    int  i=5;
    printf("%d\t",sizeof(!d));
    printf("%d\t",sizeof(i=15/2));
    printf("%d",i);
    return 0;
}

 

A.

4 2 7

B.

4 4 5

C.

2 2 5

D.

Compile Time Error: expression not allowed inside sizeof

See Answer & Explanation Lets Discuss
Correct answer is : B,C
Explanation

On a 32 bit compiler : 4 4 5

On a 16 bit compiler : 2 2 5

sizeof(Expr)  operator returns the size of the final value of the expression.

Consider the following expression:

!d = !5.2 =0

0 is int type integer constant and it's size is 4 on a 32 bit compiler..

Now, Consider the following expression:

i = 15/2

=> i = 7

=> 7

7 is an integer and Hence the size is 4 bytes.

 

Here the value of "i" changes only inside the scope of sizeof operator and the original i is not altered outside.

So value of variable "i" remains 5 in the printf statement.

 
10

What is the output of the following program?

#include<stdio.h>
int main(){
    int a= sizeof(signed) +sizeof(unsigned);
    int b=sizeof(const)+sizeof(volatile);
    printf("%d",a+++b);
    return 0;
}
A.

16

B.

8

C.

Error: Cannot find size of modifiers.

D.

Error: Undefined operator +++

See Answer & Explanation Lets Discuss
Correct answer is : A,B
Explanation

16 bit compiler prints : 8

32 bit compiler prints : 16

Default data type of signed, unsigned, const and volatile is int. 

So, a = 8 and b =8

Now, a+++b, The precedence of ++ (increment operator) is more than +(addition operator), Hence.

a+++b

= a++ + b

= 8 + 8  //4 + 4 in 16 bit compiler , due to post increment operator 

= 16  // 8 in 16 bit compiler

 
 

Banner to LogicGuns.com

Hide Page Information

Objective Questions in C with Answers

Here you can find C Objective interview questions with answers and explanation.

Where can I practice Objective Questions in C

Placement yogi will be launching online test for Objective Questions in C very shortly , in the mean time practice the questions given in the website

Why C Basics?

In this section you can learn and practice Objective Questions in C to improve your skills in order to face the interview, competitive examination and various entrance test (CAT, GATE, GRE, MAT, Bank Exam, Railway Exam etc.) with full confidence.

Where can I get Objective Questions and Answers in C with Explanation?

PlacementYogi provides you lots of fully solved C Basics questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download C Basics quiz questions with answers as PDF files and eBooks.

Where can I get C Basics Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective questions for C Basics questions and answers for interview and entrance examination. Multiple choice and true or false type questions are also provided.

How to solve Objective Questions on C Basics problems?

You can easily solve all kind of questions based on C Basics by practicing the exercises (including shortcut methods to solve problems) given below.