Loading
Tweet
Videos
Blog
News
Forum
Games
Shop
Jobs
prev
Review for Exam 2
Work, Energy, and Universal ...
Sums
Astral Alliance
Normalizing Audio for the Wh...
What Can Physics Say About L...
Introducing Photoshop CS4
Music for the Papal Liturgies
Lecture 7
Polar Coordinates
next
May 24, 2013, 06:02:20 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Welcome!
Forum Home
Help
Search Forum
Login
Register
XoaX.net Forum
>
Subjects
>
C++
(Moderator:
bluetoo
) >
Dynamic Array Allocation
Pages: [
1
]
Go Down
« previous
next »
Send this topic
|
Print
Author
Topic: Dynamic Array Allocation (Read 253 times)
Fred
Newbie
Posts: 1
Dynamic Array Allocation
«
on:
July 08, 2012, 07:37:43 PM »
Hi
Thanks for the great tutorial videos. I have a question about video 36: The following is from the video.
********************************************************
int ArraySize;
cout<<"How many integer should be stored"<< endl;
cin>>ArraySize;
int *ipIntArray =new int[ArraySize];
for (int i=0;i<ArraySize; ++i){
cout<< "input the integer number "<<i+1<<" :"<<endl;
cin>> ipIntArray
;
}
for (int i=0;i<ArraySize; ++i){
cout<<ipIntArray
<<" ";
}
cout<<endl;
delete [] ipIntArray;
***********************************************
My question is in the loop, when allocating the array elements, why shouldn't we use the dereference operator, as we do for integers? I was expecting to have something like
cin>> *ipIntArray
;
and
cout<<*ipIntArray
<<" ";
Regards
Fred
Logged
Michael Hall
Administrator
Hero Member
Posts: 903
Re: Dynamic Array Allocation
«
Reply #1 on:
July 09, 2012, 05:17:16 PM »
That's not quite right. The line
Code:
cin >> ipIntArray;
should be
Code:
cin >> ipIntArray[i];
The bracket and integer value,
i
, effectively "dereference" the
i
th element of the array. Use * when you have one element and the brackets when you have an array.
Mike
P.S. You should also use the bracket operator in your later output loop.
Logged
Pages: [
1
]
Go Up
Send this topic
|
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Subjects
-----------------------------
=> C++
===> Console
===> OpenGL
===> MFC
===> Win32
===> Visual C++ IDE
===> C++ Misc.
===> C
=> Computer Science
===> Algorithms
===> Computer Architecture
===> Graphics 3D
===> Neural Networks
===> UML
===> Development
=> Web Programming
===> PHP
===> HTML
===> CSS
===> Flash
===> Actionscript
===> Java
===> JavaScript
=> Math
=> Physics
=> English
=> Music
=> Children's
=> Software
=> Catholicism
=> Other
===> Puzzles and Tricks
===> How To Use a Computer
=> General Information
===> Site Suggestions
===> Off Topic
Loading...