3i Infotech Papers: Sample Questions 349 - 350 of 1245

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

Question number: 349

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is the output of the following program?

  1. #include<stdio.h>
  2. int getVal()
  3. {
  4.     return 1000;
  5. }
  6. void main ()
  7. {
  8.     int x=getVal();
  9.     printf(“x=%d”,x);
  10. }

Explanation

  • The program uses keyword “return” to return value a value in the caller function.

Table showing the program

Table showing the program

int getVal ()

{

return 1000;

}

  • Define the getVal () function

  • This function returns 1000.

int x = getVal ();

  • Integer variable x defines the getVal () function.

printf (“x=%d”, x);

  • Printf prints the value of x = 1000.

Question number: 350

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is the output for the program given below

  1. typedef enum errorType { warningerrorexception, }error;
  2. main ()
  3. {
  4.     error g1;
  5.     g1 = 1;
  6.     printf ( “%d” ,g1);
  7. }

Explanation

  • Compiler error: Multiple declaration for error

  • In the program

  • The name error is used with the two meanings.

  • One means that it is an enumerator constant with value 1.

  • Another use is that it is a type name (due to typedef) for enumerrorType.

  • Given a situation the compiler cannot distinguish

Table shows the program error

Table shows the program error

error g1g1 = error;

  • When the compiler can distinguish between usages then it will not issue error

  • Names canonly be overloaded in different namespaces.

  • Note: the extra comma in the declaration.

Table shows the program error

Table shows the program error

enum errorType {warning, error, exception, }

  • Is not an error. An extra comma is valid and is provided just for programmer’s convenience.