Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 225 - 227 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 225

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inta =2, ⚹f1, ⚹f2;
  4.     f1 =f2 =&a;
  5.     f2 += ⚹f2 += a += 2.5;
  6.     printf ( “ %d %d %d”, a, ⚹f1, ⚹f2);
  7. }

Explanation

In the program

Table Shows the Program
int a = 2, ⚹ f1, ⚹ f2;
  • Given the integer variable a = 2 and pointer variable f1 and f2.
f1 = f2 = &a;
  • f1 and f2 both refer to the same memory location a.
⚹ f2 += ⚹ f2 += a += 2.5;⚹ f2 =⚹ f2 + (⚹ f =⚹ f2 + (a = a + 2.5) )

a = a + 2.5 = 4

so ⚹ f2 = 4

⚹ f2 =⚹ f2 + 4 = 8

Now ⚹ f2 = 8

So, ⚹ f2 =⚹ f2 + 8 = 16

printf ( “% d % d % d” , a, ⚹ f1, ⚹ f2) ;So changes through f1 and f2 ultimately affects only the value of a.

So the answer is 16 16 16

Question 226

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Where does global, static, local, local, register variables, free memory and C program instructions get stored?

Explanation

Local is stored in the stack. Register variables are stores in the registers. Global, static variables are stored in the Heap.

Question 227

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is difference between structure and union?

Explanation

Difference between Structure and Union
StructureUnion
The keyword struct is used to define a structure.The keyword union is used to define a union.
Every member within a structure is assigned unique storage area of location.Memory allocated is shared by individual members of union.
Individual member can be accessed at a time.Only one member can be accessed at a time.
Altering value of a member does not affect the other members of the structure.Altering any one value of member will affect the other member values.
Several members of a structure can be initialized at once.Only the first member of a union can be initialized.
Structure contains all the membersUnion at runtime is only one of its members

Developed by: