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

Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inti, n;
  4.     char ⚹x =“girl”;
  5.     n =strlen(x);
  6.     x =x[n];
  7.     For( i =0; i<n;++i)
  8.     {
  9.         printf (%s, x);
  10.         x ++;
  11.     }
  12. }

Explanation

(Blank space)

irl

rl

l

In a program

Table Shows the Program
int i, n;Define integer variable I and n.
char ⚹ x = “girl” ;String (a pointer to char) is initialized with a value “girl” .
n = strlen (x) ;The strlen function returns the length of thestring, thus n has a value 4.
⚹ x = x [n] ;This statement assigns value at the nth location ( ‘⧵0’ ) to the first location. Nowthe string becomes “⧵0irl” .
For (i = 0; i < n; ++ i)

{

printf (% s, x) ;

x ++ ;

}

Printf statement printsthe string. After each iteration it increments it starting position. Loop starts from 0 to 4.
  • The first time x [0] = ‘⧵0’ hence it prints nothing and pointer value is incremented.
  • The second time it prints from x [1] i.e.. “irl”
  • The third time it prints “rl”
  • And the last time it prints “l” and the loop terminates.

Question 359

Question

MCQ▾

What is the max. decimal number that can be accommodated in a byte.

Choices

Choice (4)

a.

512

b.

125

c.

256

d.

255

Answer

d.

Explanation

  • bits.
  • A byte can represent one of these 256 district values. i.e.. numbers between (min) to (max) .
  • Thus maximum decimal number accommodated in a byte is .

Developed by: