Pointer

i just want to seek help.
i just want to know what is Pointer in C++
i also want to see some sample program of Pointer in C++.
thanks.. Ü
thanks mr. hamsterman!!it helped a bit

i want to see a sample program with it's output. 5 samples to be exact.
i need to be know this because i want to built a program using Pointers.

thanks...Ü

but this answer helped me a bit..

i want more clarrification..
Tell me exactly what is the point you don't understand?

A pointer is the memory address a value is stored in (and the amount of bytes it stores with that data type). Creating an int pointer (a pointer that can point to integers) is done like so: int* pointername; Unlike references, pointers can be given other objects to point to during runtime. Some more advanced aspects which you need not look at for the time being: Pointers can also be used to store arrays in a more flexible way and are also used for dynamic memory allocation.
@Kyon i do understand all.. all i need is samples..
samples using pointers..
thanks anyways... :D
Let's say that you have the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
int main()
{
    int Variable; // Create a new variable to store a value in
    std::cin >> Variable; // Input an integer and store it in Variable
    int* Pointer; // Create a pointer to an integer
    Pointer = &Variable; // Store the ADDRESS of Variable in it. (&Variable)
    std::cout << "Variable:" << Variable << std::endl; // Show the value of Variable
    std::cout << "Pointer:" << Pointer << std::endl; // Show the address store in Pointer
    std::cout << "*Pointer:" << *Pointer << std::endl; // Show the value that the address in Pointer points to (is equal to Variable)
    std::cout << "&Variable:" << &Variable << std::endl; // Show the address  that the value of Variable is store in (is equal to Pointer)
    system("pause"); // Pause the console window
    return 0;
}


A small very basic example.
thanks alot!!!!i really appreciate the help!!!!
need some more samples...basic or even hard samples...

thank you for the help....

i owe to you guys my success :D
OHH I GOT ONE!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//THIS GOES IN MAIN
int MyInt = 0;
int set = 0;
std::cout << "MyInt: " << MyInt << "\nSet to: ";
std::cin >> set;
setInt(&MyInt,set);
std::cout << "\nstd::cin >> set;\nsetInt(" >> &MyInt >>"," >> set >> ");";
std::cout << "\nMyInt: " << MyInt;
system("pause"); //EDIT: PAUSE!
//THIS IS A FUNCTION OUTSIDE OF MAIN
//setInt(&var,NUMBER);
void setInt(int *out, int in) {
    *out = in;
}
//setInt(&var,&variable or pointer);
void setInt_p(int *out, int *in) {
    *out = *in;
}
/*
OUTPUT:
MyInt: 0
Set to: 8 OR WHATEVER
std::cin >> set;
setInt([ADDRESS],8);
MyInt: 8
Press any key to continue...
*/
Last edited on
oh thank you so much!!!firefly431..
3 more to go and i will understand this!!!!!!

firefly431 thanks a lot!!
Topic archived. No new replies allowed.