*ptr is a pointer and [10] is array is array declaration.
Neha said:
(Fri, Sep 10, 2010 10:42:03 AM)
Can you explain me the concept?
Ravikumar said:
(Fri, Oct 1, 2010 03:20:21 PM)
We can use a * sometimes to declare the array both are same that is way answer is b.
Vijayalaxmi said:
(Sun, Oct 3, 2010 04:11:25 AM)
Here we have to see the priority () have highest priority.
So int (*ptr)[] read it as pointer to array of integers.
If () is not there then int *ptr[] start with [] and it means array of pointers of type integers.
Avijit said:
(Thu, Oct 28, 2010 12:04:03 PM)
ptr is a pointer,which is a type of int.ptr is an array.
Kuldeep Chaudhary said:
(Tue, Nov 16, 2010 06:24:11 AM)
pointer of array is declared as type (*p)[14]
array of pointers is declared as type *p[14]
Gautam Jangra said:
(Fri, Nov 26, 2010 03:30:34 AM)
int (*ptr)[10]
also we can write it as
int *ptr[10]
this line says that ptr is a pointer type variable which stores the address of first element of a 10 elements array list
as we know that array is continous memory type allocation.....
Neeraj Awasthi said:
(Sun, Nov 28, 2010 09:19:38 AM)
If () is not there then int *ptr[] start with [] and it means array of pointers of type integers.
Nagaraj said:
(Thu, Dec 30, 2010 05:11:54 AM)
The below program explains tat the starting address of the array. so it is [int (*ptr)[5];] is a pointer to array not array pointer which can be declared by int *ptr[5];
#include<stdio.h>
int main()
{
int arr[5];
int (*ptr)[5];
ptr=&arr[10];
printf("%ld",ptr[5]);
return 0;
}
Subaidha said:
(Fri, Jan 21, 2011 01:31:00 AM)
* means its represent as a pointer variable and here within a array bracket they give us 10 integers.
So that the ans is B.
Balaji said:
(Wed, Feb 23, 2011 08:14:42 AM)
Can you explain me the concept?
Purna Chandra said:
(Thu, Feb 24, 2011 04:45:08 AM)
Yes p is pointer of 10 integers.
Ganesh said:
(Tue, Apr 12, 2011 03:31:48 AM)
*ptr is a pointer and[10] is array declarations.
Lol said:
(Fri, May 6, 2011 04:32:13 AM)
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
Chris said:
(Thu, Jun 23, 2011 08:01:05 AM)
#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 ?
Sundar said:
(Thu, Jun 23, 2011 08:10:00 AM)
@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.
Apurva Nigam said:
(Sun, Jun 26, 2011 02:37:08 PM)
@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....
Raghu said:
(Tue, Aug 9, 2011 04:43:12 PM)
Any one can explin main difference between a[] & *ptr[] with an example.
Sid... said:
(Thu, Sep 1, 2011 09:58:15 PM)
*ptr (10) means.
It is a pointer type aaray whch have 10 integers in it.
Ssk said:
(Thu, Sep 8, 2011 01:03:15 PM)
@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:)
Padmanaban said:
(Thu, Sep 15, 2011 12:45:57 AM)
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...!!!!!
Mayank Dixit said:
(Sun, Sep 18, 2011 11:22:41 AM)
*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.
Vijay Kanth &Amp; Prasanth Krishna said:
(Wed, Oct 19, 2011 03:11:57 PM)
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).
Nitin Goyal said:
(Sun, Nov 6, 2011 12:42:11 PM)
Here ptr is the pointer for the memory location occupied by array having 10 elements.
Gaurav said:
(Sun, Jan 22, 2012 11:21:55 PM)
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....
Divya said:
(Wed, Jan 25, 2012 05:03:47 PM)
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).