Showing posts with label Arrays. Show all posts
Showing posts with label Arrays. Show all posts

Thursday, 19 January 2012

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

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


1)

main( )

{

int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};


printf(“%u %u %u %d \n”,a,*a,**a,***a);


printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);


}

Answer:

100, 100, 100, 2


114, 104, 102, 3


Explanation:

Friday, 18 November 2011

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

const int size = 5;

void print(int *ptr)

{

cout<<ptr[0];


}

void print(int ptr[size])

{

cout<<ptr[0];


}

void main()

{

int a[size] = {1,2,3,4,5};


int *b = new int(size);


print(a);


print(b);


}

Answer:

Compiler Error : function 'void print(int *)' already has a body

Explanation:

Friday, 11 November 2011

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

#include<stdio.h>

main()

{

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };


int *p,*q;


p=&a[2][2][2];


*q=***a;


printf("%d----%d",*p,*q);


}

Answer:

SomeGarbageValue---1

Explanation:

Thursday, 27 October 2011

Sun Certified Java Programmer (SCJP)

Declarations and access control


Arrays


Arrays are dynamically created objects in Java code. An array can hold a number of variables of the same type. The variables can be primitives or object references; an array can even contain other arrays.

Declaring array variables


When we declare an array variable, the code creates a variable that can hold the reference to an array object. It does not create the array object or allocate space for array elements. It is illegal to specify the

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