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 2 of 7.
Subaidha said:
1 decade ago
* means its represent as a pointer variable and here within a array bracket they give us 10 integers.
So that the ans is B.
So that the ans is B.
Balaji said:
1 decade ago
Can you explain me the concept?
Purna chandra said:
1 decade ago
Yes p is pointer of 10 integers.
Ganesh said:
1 decade ago
*ptr is a pointer and[10] is array declarations.
LOL said:
1 decade ago
The brackets are the key to this problem. Always read C declarations from right to left (backwards) and start will stuff inside brackets.
[] = array * = pointer
int *ptr [10] backwards is [10] ptr * int
so this is Array of 10 pointers to int
int (*ptr)[10] bracket first and backwards is * ptr [10] int
so this is pointer to an array of 10 integers
[] = array * = pointer
int *ptr [10] backwards is [10] ptr * int
so this is Array of 10 pointers to int
int (*ptr)[10] bracket first and backwards is * ptr [10] int
so this is pointer to an array of 10 integers
Chris said:
1 decade ago
#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d %d %d", a++, a--, ++a, --a, a);
return 0;
}
// Ans : 4 5 5 4 5
Can any one explain the above code please ?
int main()
{
int a=5;
printf("%d %d %d %d %d", a++, a--, ++a, --a, a);
return 0;
}
// Ans : 4 5 5 4 5
Can any one explain the above code please ?
Sundar said:
1 decade ago
@Chris
The given output '4 5 5 4 5' is matches in Turbo C - 16 OS (DOS).
But, I tried in GCC, the details are as below:
Warnings:=
prog.c: In function 'main':
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
Output:=
4 5 5 5 5
Please can anyone explain with full details here. Thanks in advance.
The given output '4 5 5 4 5' is matches in Turbo C - 16 OS (DOS).
But, I tried in GCC, the details are as below:
Warnings:=
prog.c: In function 'main':
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
Output:=
4 5 5 5 5
Please can anyone explain with full details here. Thanks in advance.
Apurva Nigam said:
1 decade ago
@Chris and @Sundar:
"printf("%d %d %d %d %d", a++, a--, ++a, --a, a); " evaluates the value passed in it from right to left(int turbo C).
That is
first "a" will get its value as 5
then --a will store 4
then ++a will store 5 (as "--a" had decremented a's value n ++a incremented it)
then "a--" will have 5 ( as a-- is post increment therefore a's value will be affected after evaluation of the expression "a--")
then "a++" will have value 4 (b'coz above "a--" has made its value 4)
Therefore output is: 45545
Hope u know preincrement increments the value first and then use it in the expression, whereas postincrement uses the previous value of the variable and then modifies it thet is increments by 1.
eg:
int x=5 ,y,z;
y= ++x; //first x will become 6 then y will get assigned 6
z= x++; //first x will get assigned in z that is z=6 then x gets incremented.
Good night :) :)
Hope u understood....
"printf("%d %d %d %d %d", a++, a--, ++a, --a, a); " evaluates the value passed in it from right to left(int turbo C).
That is
first "a" will get its value as 5
then --a will store 4
then ++a will store 5 (as "--a" had decremented a's value n ++a incremented it)
then "a--" will have 5 ( as a-- is post increment therefore a's value will be affected after evaluation of the expression "a--")
then "a++" will have value 4 (b'coz above "a--" has made its value 4)
Therefore output is: 45545
Hope u know preincrement increments the value first and then use it in the expression, whereas postincrement uses the previous value of the variable and then modifies it thet is increments by 1.
eg:
int x=5 ,y,z;
y= ++x; //first x will become 6 then y will get assigned 6
z= x++; //first x will get assigned in z that is z=6 then x gets incremented.
Good night :) :)
Hope u understood....
Raghu said:
1 decade ago
Any one can explin main difference between a[] & *ptr[] with an example.
Sid... said:
1 decade ago
*ptr (10) means.
It is a pointer type aaray whch have 10 integers in it.
It is a pointer type aaray whch have 10 integers in it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers