3i Infotech Papers: Sample Questions 843 - 844 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 843

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Find the output of the following program

  1. Void main()
  2. {
  3.     int a, *pa, &ra;
  4.     pa = &ara = acout <<"a=”;
  5. }

Explanation

  • In the program

Table showing the program

Table showing the program

int a, *pa, &ra;

  • Define the integer variable a, pointer pa and reference of ra

pa = &a;

  • Pointer ‘pa’ assigned the address of ‘a’

ra = a;

  • Reference ‘ra’ assigned the address of ‘a’

cout < < “a=”;

  • Prints the value of a

  • Here pointers are different from references.

  • One of the main differences is that the pointers can be both initialized and assigned, whereas references can only be initialized.

  • Compiler Error: ‘ra’ reference must be initialized

  • So, this code issues an error.

Question number: 844

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is the output of the following program?

  1. #include<stdio.h>
  2. void main ()
  3. {
  4.     int a[2][2][2] = { { 102}, { 56} };
  5.     int * p, * q;
  6.     p = &a[2][2][2];
  7.     q = * * * a;
  8.     printf ( “%d…%d” * p, * q);
  9. }

Explanation

In the program

Table shows the program

Table shows the program

int a [2] [2] [2] = { {10,2}, {5,6} };

  • Given the integer 2D array and values

int * p, * q;

  • Given the integer pointer and q

p = &a [2] [2] [2];

  • p = &a [2] [2] [2] declares only two dimensions 2D arrays.

  • But trying to access the third dimension (which was not declared) will print garbage values.

* q =* ** a;

  • q =* ** a starting address of a is assigned integer pointer.

  • Now q is pointing to starting address of a.

  • If you print * q it will print first element of 3D array