in Unknown Category
5,193 views
0 votes
0 votes
Of the following expressions I A[2] II A[2][3] III B[1] IV B[2][3] which will not give compile-time errors if used as left hand sides of assignment statements in a C program?
 
I, II, and IV only
B
II, III, and IV only
C
II and IV only
 
IV only
in Unknown Category
by
5.2k views

3 Comments

Ans-  C
0
0
#include<stdio.h>
void main()
{

        int *A[2];
        int i = 5;
        A[2] = &i;
        printf("\n%d\n", *A[2]);
}

you can try this, it works, so A[2] can be on left and side

0
0
yes ..you are right :)
0
0

1 Answer

1 vote
1 vote
int *A[10] can be pronounced as, A is a array of 10 pointers to integers,

that means A can store 10 integer pointers, A is like a 2D matrix with 10 rows, but length of each row may differ

on other hand, int B[10][10] , B is matrix of 10 row x10 column

now lets talk about options,

1, A[2] = ***

   here you can assign, address of integer variable to A[2] pointer or you can assign address of integer array to A[2], so this is TRUE

2. A[2][3] = integer_value

   this is extension to 1, here we are assigning value to 3rd location of of array which is pointed by A[2]

A[0] ->

A[1] ->

A[2] -> [2,3,4,5,6,7]  ,          so this is TRUE

 

3. B[1] = ***

    once you declare like, int B[2][3], B becomes a constant pointer, we can not make B to point some other array

    thats the reason we use pointer, like int *A[3]   this gives us flexibility

    so this is false

4. B[2][3] = value

       this is true, because we are just assigning value to memory location in 2D array

so 1,2,4 are true, hence option A

4 Comments

I apologize....I only read the description.
0
0
just a little advice, I lost my precious marks by silly mistake of not reading question correctly,

so read question carefully
0
0
thanks!!
0
0

Related questions