C Programming - Arrays - Discussion
Discussion Forum : Arrays - General Questions (Q.No. 2)
2.
What does the following declaration mean?
int (*ptr)[10];
int (*ptr)[10];
Discussion:
64 comments Page 3 of 7.
Ssk said:
1 decade ago
@Chris:
Turbo C uses __Cdecl__ type of Argument Passing mechanism in which rightmost arg is passed 1st and leftmost at atlast..
In printf(), as u might know, the leftmost format specifier is associated with leftmost value,but due to __Cdecl__, the evaluation of values is done from rightmost position..
So, 1st %d -> a++
2nd %d -> a--
3rd %d -> ++a
4th %d -> --a
5th %d -> a
This is binding is done,but as rightmost is evaluated 1st,
5th %d has value of a(5)
4th %d has --a(4) as preincrement has higher priority
3rd %d has ++a(5)
2nd %d has a--(5) as post increment is done after assignment
1st %d has a++(4) same reason as above..
So the output is as given..
Hope u have understood..
gd:)
Turbo C uses __Cdecl__ type of Argument Passing mechanism in which rightmost arg is passed 1st and leftmost at atlast..
In printf(), as u might know, the leftmost format specifier is associated with leftmost value,but due to __Cdecl__, the evaluation of values is done from rightmost position..
So, 1st %d -> a++
2nd %d -> a--
3rd %d -> ++a
4th %d -> --a
5th %d -> a
This is binding is done,but as rightmost is evaluated 1st,
5th %d has value of a(5)
4th %d has --a(4) as preincrement has higher priority
3rd %d has ++a(5)
2nd %d has a--(5) as post increment is done after assignment
1st %d has a++(4) same reason as above..
So the output is as given..
Hope u have understood..
gd:)
Padmanaban said:
1 decade ago
I have got that ++a is pre-increment so it will increment and then assign the value.
Similarly a++ means it assigns and then increment so its value cannot be printed by this only it shows the value what we assigned..... clear per-increment post-increment is the concept used there...!!!!!
Similarly a++ means it assigns and then increment so its value cannot be printed by this only it shows the value what we assigned..... clear per-increment post-increment is the concept used there...!!!!!
Mayank Dixit said:
1 decade ago
*ptr[10] means 'ptr is an array of pointer type 10 elements'.
(*ptr)[10] means there is an array of 10 elements with no array varaible but 'ptr is pointer type variable' that has base address of that array.
(*ptr)[10] means there is an array of 10 elements with no array varaible but 'ptr is pointer type variable' that has base address of that array.
Vijay kanth & prasanth krishna said:
1 decade ago
int (*ptr)[10];
here "ptr" is name of array,[10] is index of that array.
but '*'-it denotes the pointer varable is created of specified name. name-(ptr).
here "ptr" is name of array,[10] is index of that array.
but '*'-it denotes the pointer varable is created of specified name. name-(ptr).
Nitin Goyal said:
1 decade ago
Here ptr is the pointer for the memory location occupied by array having 10 elements.
Gaurav said:
1 decade ago
int (*arr)[10] /* It refers that arr is a pointer to an array of 10 integers*/
and,
int *arr[10] refers to an array of pointers which can hold the starting address of 10 different array of integer data type....
and,
int *arr[10] refers to an array of pointers which can hold the starting address of 10 different array of integer data type....
Divya said:
1 decade ago
int (*ptr)[10];
Start reading what ever is in brackets 1st ,(ptr is a pointer)
Then go towards left till you hit ; (to an array of 10)
Then go backwards and read what ever is left out, (integers).
Start reading what ever is in brackets 1st ,(ptr is a pointer)
Then go towards left till you hit ; (to an array of 10)
Then go backwards and read what ever is left out, (integers).
Goyal said:
1 decade ago
int(*ptr)[10]
Vishwaschaurasiya said:
1 decade ago
int (*ptr)[10];
ptr is a pointer, but this declaration is called pointer of an array..
Since,(*) this is unary oprator,known as (Astrick);
ptr is a pointer, but this declaration is called pointer of an array..
Since,(*) this is unary oprator,known as (Astrick);
Sasi said:
1 decade ago
int (*ptr) [10].
We can take this a cyclic check and everyone can read it easily by this way.
Start with ptr as it is a pointer go clock wise the next comes as array of size 10 that means ptr is a pointer to an array of 10 and the return type is int so it is finally as:.
ptr is a pointer to an array of 10 integers.
We can take this a cyclic check and everyone can read it easily by this way.
Start with ptr as it is a pointer go clock wise the next comes as array of size 10 that means ptr is a pointer to an array of 10 and the return type is int so it is finally as:.
ptr is a pointer to an array of 10 integers.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers