Because its an array. Char only holds 1 character
Pointers
I read this and I kind of understand it...
You use ted = &var to say ted points to address of var
You use *ted to say value pointed by ted
You use * var to declare a pointer of the type that precedes it.
I don't understand the arrays part...
I use the code:[php]
char array[] = "hello there";
[/php]
and it works, so why wouldn't
[php]
array = "hello there";
[/php]
not be valid? I don't understand...
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Because its an array. Char only holds 1 character
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Hell_Demon (08-11-2010)
Koreans speaks the truth. The compiler won't allow that, ever...
Here is a simple program that creates a pointer to an integer
[php]#include <iostream>
using namespace std;
int main()
{
int apple = 5;
int *pApple = &apple;
cout << *pApple << '\n';
return 0;
}
[/php]
Output:
Since pApple points to apple, when we [php]cout << *pApple;[/php] were really getting the value of appleCode:5
REMEMBER: Initialize a pointer to something or else youll have a wild pointer and can cause unwanted behavior. Even if youre not using it right away, initialize it to 0
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Then just leave the default value wild and re-assign it later. Same results.. |:
Anyways, arrays are basically pointers..
[php]
int array[] = {1,2,3,4,5};
[/php]
To access the last integer in the array, you can either use the brackets ( arrays ).
[php]
cout << array[4];
[/php]
Or you can use pointers.
[php]
cout << *(array+4);
[/php]
Remember, the first element is always 0, so if you have 5, the last one is going to be 4. Incase you didn't already know.
VvITylerIvV (08-10-2010)
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL