Search Placementyogi.com
 

C Declarations and Initializations Objective Questions and Answers

  :: Topics ::

1

Identify which are declarations? (select 2)

A.

double pow(double,double);

B.

float squar(float a){}

C.

float b;

D.

extern int a;

See Answer & Explanation Lets Discuss
Correct answer is : A,D
Explanation
double pow(double,double); /* Declaration */
float squar(float a){} /*Definition*/
float b; /*Definition*/
extern int a; /*Declaration*/

Before using any variable or function it should be declared. Declaration and definition can be in single statement. 

 
2

One c program is written in 2 files

/*Program1.c*/
int x=10

/*Program2.c*/
#include "Program1.c"
int main()
{
   extern int x;
   printf("x : %d",x);

}

In Program2.c statement extern int x; is not needed.

A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

When Program1.c is included in Program2.c, So we can say that all content of Program1.c is copied to Program2.c before compilation.

 

Now int x is available to program2.c so no need of extern int x; statement. it is required when in Program2.c , Program1.c is not included.  

 
3

A function can have several declaration, but only one definition?

A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

No explanation available. Let's Discuss

 
4

Which of the following is the correct output of the program?

#include<stdio.h>
int main()
{
    int a[5]={9,10};
    printf("%d,%d",a[1],a[2]);
    return 0;
}
A.

9, 10

B.

10, 0

C.

0, 0

D.

0, 9

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

When an automatic array or structure are partially initialized, the remaining array elements are initialized to zero.

Ex. a[0] = 9, a[1] = 10, a[2] = 0, a[3] = 0, a[4] = 0

 
5

What is the output of following program?

#include<stdio.h>
int main()
{
  void *ptr1, *ptr2, x;
  int y;
  x = 100;
  y = 200;
  
  ptr1 = &x;
  ptr2 = &y;
  
  printf("%d", *ptr1);
  pritnf("%d", *ptr2);  
   
  return 0;
  
}
A.

error: variable or field x declared void

B.

100,200

C.

garbage value , 200

D.

None of above

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

We can declare a void pointer but not a simple variable of type void.

 

In above program size of x is unknow or zero because it is declared as void so compiler throws error!

 

even below program throws error : variable or field x declared void

#include<stdio.h>
int main()
{
  void x;

}
 
 

Banner to LogicGuns.com

Hide Page Information

C Declarations and Initializations Objective Questions and Answers

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

Why C Declarations and Initializations?

In this section you can learn and practice C Declarations and Initializations (Questions with Answers) 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 C Declarations and Initializations Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Declarations and Initializations 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 Declarations and Initializations quiz questions with answers as PDF files and eBooks.

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

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

How to solve C Declarations and Initializations problems?

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