Languages [3i Infotech Placement]: Sample Questions 177 - 178 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 177

Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. #include<stdio.h>
  2. intgetVal()
  3. {
  4.     return1000;
  5. }
  6. voidmain ()
  7. {
  8.     intx=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
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 178

Edit

Describe in Detail

Essay▾

What is the output for the program given below

  1. typedefenumerrorType { warning, error, exception, }error;
  2. main ()
  3. {
  4.     errorg1;
  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
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
enum errorType {warning, error, exception,}
  • Is not an error. An extra comma is valid and is provided just for programmer՚s convenience.

Developed by: