retagged by
366 views
0 votes
0 votes

I have confusion regarding pointers, why 1D array and 2D array works differently. For e.g. I have written a code

#include <stdio.h>

int main(){
    int arr[6]={1,2,3,4,5,6};
    int marr[3][3]={11,22,33,44,55,66,77,88,99};
    printf("%d\n",*arr);
    printf("%d",*marr);
    return 0;
}

//-----------------output-------------------------------------
bleepblop@bleep-M-74EW C_Program % gcc -o array array.c
array.c:8:14: warning: format specifies type 'int' but the argument has type 'int *' [-Wformat]                                                                                                          
        printf("%d",*marr);            
                ~~  ^~~~~                   
1 warning generated.
bleepblop@bleep-M-74EWC_Program % ./array
1   
-1167960528

 

isn’t *marr suppose to print ‘11’ in place of some longed signed value.

retagged by

1 Answer

3 votes
3 votes
Here put **marr then it will give 11 as output because

*marr will point to the 1 d array means first row and hence it  returns address of first row

**marr will return value at the address which will be 11

Related questions

2 votes
2 votes
0 answers
2
Na462 asked Oct 20, 2018
2,029 views
What is the Output of following Array ? A. 8 10B. 10 8C. 10 2D. 8 1E. Garbage value
1 votes
1 votes
1 answer
3
radha gogia asked Jul 10, 2018
1,740 views
If I have an array :int a [3][4] ; How to evaluate below Outputs ? 1. sizeof(*a) 2.sizeof( a) 3. sizeof(a) Please explain precisely .
3 votes
3 votes
2 answers
4