Accenture Placement: Sample Questions 3 - 4 of 9

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 3

Edit

Describe in Detail

Essay▾
  1. Main ()
  2. {
  3.     externinti;
  4.     i=20;
  5.     printf(“%d” i);
  6. }

Explanation

Extern is a key word in C that indicates the scope of a variable or function.

extern int i;

Table Shows the Program
Extern int iDeclare the extern integer i
i = 20Integer value is 20
Printf ( “% d” i)i is available in any other program with memory space allocated for it.

During linking the linker searches for the definition of i.

So, it is not found the linker flags an error.

So generate Linker Error: Undefined symbol ‘_i’

Question 4

Edit

Describe in Detail

Essay▾
  1. main()
  2. {
  3.     inti=3;
  4.     switch (i)
  5.     {
  6.         default:printf(“zero”);
  7.         case1:printf(“one”);
  8.         break;
  9.         case2:printf ( “two” );
  10.         break;
  11.         case3:printf ( “three” );
  12.         break;
  13.     }
  14. }

Explanation

Given i = 3

Table Shows the Program
Int i = 3Given integer variable i = 3
  1. switch (i)
  2. {
  3.     default:Printf(“zero”);
  4.     case1:Printf(“one”);
  5.     break;
  6.     case2:Printf ( “two” );
  7.     break;
  8.     case3:Printf ( “three” );
  9.     break;
  10. }
In this switch condition case 3 (i = 3) is selected

As there is a break statement after it, it comes out of the switch

So, answer is three.

Developed by: