Search Placementyogi.com
 

C Structures And Unions Advanced Objective Questions and Answers

  :: Topics ::

1

Below program compiles successfully.

#include<stdio.h>
int main()
{
  struct student
  {
    int id;
    char name[20];
   };

   struct student a;
   a.id=20;
   a.name="PlacementYogi";

   printf("%d,%s",a.id,a.name);

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

name[] is an array. 

So, char name[20] ="PlacementYogi"; is allowed 

 but char name[20];

     name="PlacementYogi"; is not allowed

because here we are trying to store something in base address of array which is constant.

 
2

 What will be the output of the program?

#include<stdio.h>
struct number
{
  int n1:1;
  int n2:4;
  int n3:5;
}num={1,15,15};

int main()
{
  printf("%d,%d,%d",num.n1, num.n2,num.n3);
}
A.

1,15,15

B.

-1,15,15

C.

-1,-1,15

D.

-1,-1,-1

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

Note: In int n1:1; 'int' is a signed ineger and ':1' fix the width of n1 to 1 bit.

1 means -ve, 0 means +ve

Ex. n1=1; binary of one is 1, left most bit is 1, so -ve number.

    printed value will be the 2's complement of 1 with -ve sign. i.e -1

 

In case of int n2:4; and n2=15;

Binary of 15(4 bit) => 1111, left most bit is 1, so -ve,

2's complement of 1111 =>  1's complement + 1

                                  =>  0000 + 1 

                                  =>  1

printed value = -1 ( 2's complement with -ve sign)

 

In case of int n2:4; and n2=15;

Binary of 15(5 bit) => 01111, left most bit is 0, so +ve,

If +ve, it will be printed without any conversion i.e 15 

 
 

Banner to LogicGuns.com

Hide Page Information

C Structures And Unions Advanced Objective Questions and Answers for Written Round Interview

Here you can find C Structures And Unions Advanced Objective Questions with answers and explanation. We have a vast collection of Objective Questions on Structures And Unions Advanced in C that will help you a lot!

Why learn C Structures And Unions Advanced?

Structures And Unions Advanced are an integral part of C and many Objective Questions in the written round are asked from this topic.In this section you can learn and practice C Structures And Unions Advanced (Objective Questions with Answers) to improve your skills in order to face the interview and clear campus and off-campus selection of TCS, Infosys, Wipro etc.

Where can I get C Structures And Unions Advanced Objective Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Structures And Unions Advanced Objective Questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand.Though we do not have pdf file for C Structures And Unions Advanced, We have quiz Objective Questions with answers to help you test yourself..

\n

Where can I get C Structures And Unions Advanced Interview Objective Questions and Answers (objective type, multiple choice)?

Here you can find objective type C Structures And Unions Advanced Objective Questions and answers for interview and entrance examination.Multiple Answers and true or false type Objective Questions are also provided.

How to solve C Structures And Unions Advanced problems?

You can easily solve all kind of Objective Questions based on C Structures And Unions Advanced by practicing the exercises (including shortcut Structures And Unions Advanced to solve problems) given below.