Showing posts with label lvalue. Show all posts
Showing posts with label lvalue. Show all posts

Tuesday, 24 January 2012

Frequently Asked Questions in Technical Round at MNCs like TCS, WIPRO, INFOSYS,..etc – 5

Predict the output or error(s) for the following:


1)

main( )

{

 static int  a[ ]   = {0,1,2,3,4};


 int  *p[ ] = {a,a+1,a+2,a+3,a+4};


 int  **ptr =  p;


 ptr++;


 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);


 *ptr++;


 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);


 *++ptr;


 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);


 ++*ptr;


printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);


}

Answer:

111


222


333


344


Explanation:

Monday, 2 January 2012

Frequently Asked Questions in Technical Round at MNCs like TCS, WIPRO, INFOSYS,..etc - 1

Predict the output or error(s) for the following:


1)

main()

{

static char names[5][20]={"pascal","ada","cobol","fortran","perl"};


int i;


char *t;


t=names[3];


names[3]=names[4];


names[4]=t;


for (i=0;i<=4;i++)


printf("%s",names[i]);


}

Answer:

Compiler error: Lvalue required in function main


Explanation:

Tuesday, 25 October 2011

Can an array be an lvalue?

In the last post, an lvalue was defined as an expression to which a value can be assigned. Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several separate array elements that cannot be treated as a whole for assignment purposes. The following statement is therefore illegal:

int x[5], y[5];
x = y;

You could, however, use a for loop to iterate through each element of

Saturday, 22 October 2011

What is an lvalue?

An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant. For instance,