Languages [3i Infotech Placement]: Sample Questions 512 - 513 of 546

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

Question 512

Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     int ⚹i =0 × 400;//i points to the address 400
  4.     i =0; //set the value of memory location pointed by i;
  5. }

Explanation

In the program

Table Shows the Program
int ⚹ i = 0 × 400;
  • Given the integer pointer i = 0 × 400
⚹ i = 0;
  • This statement results in undefined behavior because it points to some location whose value may not be available for modification.
  • Pointer with non-availability of the implementation of the referenced location is known as ‘incomplete type’ .

Question 513

Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. typedefstructerror { intwarning, error, exception; }error;
  2. main ()
  3. {
  4.     errorg1;
  5.     g1. error =1;
  6.     printf ( “%d” ,g1. error);
  7. }

Explanation

In the program three usages of name “error” are distinguishable by the compiler at any instance, hence are valid (they are in different namespaces) .

Table Shows the Program
Typedef struct error {int warning, error, exception;} error;
  • This “error” can be used only by preceding the error by struct keyword as in:

    struct error someError;

    typedef struct error {int warning, error, exception;} error;

  • This can be used only after. (dot) or ⇾ (arrow) operator preceded by the variable
g1. error = 1;

printf ( “% d” , g1. error) ;

  • typedef struct error {int warning, error, exception;} error;
  • This can be used to define variables without using the preceding struct keyword as in:
  • error g1;
  • Since the compiler can distinguish between these three usages, it is legal and valid.

Note: This code is given here to just explain the concept. In real programming don՚t use such overloading of names. It reduces the readability of the code.

Developed by: