•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,974 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,754 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2518 | Replies: 4
![]() |
•
•
Join Date: Jul 2004
Posts: 64
Reputation:
Rep Power: 5
Solved Threads: 0
#include <iostream>
using namespace std;
int main()
{
int age;
for (int i=0;i<5;i++)
{
cout << "Enter :";
cin >> age;
}
int *sum=&age;
for ( i=0;i<5;i++)
{
cout <<*(sum+i) << endl;
}
return 0;
}
here is one of my program that i wrote.
i do not know whats the problem with it.
it seems can't display back the values that i've entered in.
can sir/miss help me to correct my mistake(s).
Thank you!
using namespace std;
int main()
{
int age;
for (int i=0;i<5;i++)
{
cout << "Enter :";
cin >> age;
}
int *sum=&age;
for ( i=0;i<5;i++)
{
cout <<*(sum+i) << endl;
}
return 0;
}
here is one of my program that i wrote.
i do not know whats the problem with it.
it seems can't display back the values that i've entered in.
can sir/miss help me to correct my mistake(s).
Thank you!
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
int age;
An array is declared:
datatype array_name[int_size];
Eg. int vals[10];
int *p = vals;
Then p[0] = vals[0] and p[1] = vals[1] and so on.
Also you can access the vals by *(p+i) instead of the [], and the expression is read as the value at the address of p+i.
An array var is also a pointer so you dont need a & in front of it when you assign it to another pointer.But if you want to just point to a single int for example:
int *p = &val; //means p = address of val
and you can access the value a the address pointed to by p usinf another_int = *p ;
---Helps???
datatype array_name[int_size];
Eg. int vals[10];
int *p = vals;
Then p[0] = vals[0] and p[1] = vals[1] and so on.
Also you can access the vals by *(p+i) instead of the [], and the expression is read as the value at the address of p+i.
An array var is also a pointer so you dont need a & in front of it when you assign it to another pointer.But if you want to just point to a single int for example:
int *p = &val; //means p = address of val
and you can access the value a the address pointed to by p usinf another_int = *p ;
---Helps???
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- problem with freeing memory (C)
- problem relating to c program.... (Techies' Lounge)
- Hi i'm having trouble with writing a program (C)
- Deleting a pointer? (C++)
- Program Problem with a select statement to access Data base (C)
Other Threads in the C++ Forum
- Previous Thread: Input a "password" string
- Next Thread: New to C++ Pointers and need help with identifying where the errors are



Linear Mode