C Programming - Pointers - Discussion

Discussion Forum : Pointers - Point Out Correct Statements (Q.No. 6)
6.
Which of the statements is correct about the program?
#include<stdio.h>

int main()
{
    int arr[3][3] = {1, 2, 3, 4};
    printf("%d\n", *(*(*(arr))));
    return 0;
}
Output: Garbage value
Output: 1
Output: 3
Error: Invalid indirection
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
27 comments Page 2 of 3.

Niki said:   1 decade ago
Can we take it like this?

*(*(*(arr))=*(*(*arr[0][0]))=*(*(1))

Some one please explain me.

Rushit said:   1 decade ago
@Lavaanya.

*(arr+1) is one unit here it shifts 3(cause 3 row).

So. it will point to next column.

You can access any element via this = *(*(arr+column)+row).

Lavanya said:   1 decade ago
#include<stdio.h>

int main()
{
int arr[3][3] = {1, 2, 3, 4};
printf("%d\n", *(*(arr+1)));
return 0;
}

Why is answer 4 here.

Rajpati Verma said:   1 decade ago
Array declared are two dimensional but in the we want to print three dimensional value due to this reason type is not match so it thrown error.

Farzana Shaik said:   1 decade ago
We use triple pointer for 3-Dimensional array only.

But in above program 2-dimensional array is given.

@Singh said:   1 decade ago
9 element should be present their is only 4 other value can be assign as 0 or garbage value.

Manju said:   1 decade ago
Array declared as two dimensional but in the printf statement there is three dimensional pointer notation so complier thrown error.

Kunal said:   1 decade ago
As we have given two dimensional error so it can have only pointer to pointer means only two *.

Inderpal said:   1 decade ago
@ WIKIOK right answer.....

Shrikant said:   1 decade ago
Thanks Wikiok


Post your comments here:

Your comments will be displayed after verification.