3i Infotech Papers: Sample Questions 785 - 786 of 1245

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

Question number: 785

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Find the output for the following C program

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     char s1[] = “Ramco”;
  5.     char s2[] = “Systems”;
  6.     s1 = s2;
  7.     printf ( “%s” ,s1);
  8. }

Explanation

  • In the program

Table showing the program

Table showing the program

char s1 [] = “Ramco”;

  • define the character array s1 [] =”Ramco”

char s2 [] = “Systems”;

  • define the character array s2 [] =”Systems”

s1 = s2;

  • Here s2 is assigned to s1 but not s1 is not a modifiable lvalue it is fixed array.

  • An lvalue refers to an object that persists beyond a single expression. You can think of an lvalue as an object that has a name. All variables, including nonmodifiable variables are lvalues

L value assingnment

L Value Assingnment

L value assingnment

Question number: 786

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is the output of the following program?

  1. #include <stdio.h>
  2. main ()
  3. {
  4.     int xy = 2za;
  5.     if (x = y%2z = 2;
  6.     a = 2;
  7.     printf ( “%d %d” zx);
  8. }

Explanation

  • In the program

Table shows the program

Table shows the program

int x, y = 2, z, a;

Declare and define the integer variables x, z, a and y = 2

if (x = y%2) z = 2;

  • The value of y % 2 (remainder) is 0.

  • This is assigned to x.

  • The condition reduces to if (x) or in other words if (0) and z goes in initialized.

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

Printf prints the garbage value of z and x as 0

  • Thumb rule: check all control paths to write bug free code.