C
chessc4c6
The program below creates a char pointer call charPtr...... i then
declare an char array string[10] "Good Luck"
When i assign charPtr = string, I expect an error. However, It
actually runs and outputs:
G
Good Luck
Can someone explain to me how charPtr = string actually works, but if I
create
char string = 'x';
wouldn't work.
#include<math.h>
#include<iostream>
using namespace std;
void main()
{
int value;
value = 500;
char* charPtr;
char string[10] = "Good Luck";
charPtr = string;
cout<< *charPtr<<endl;
cout<<charPtr<<endl;
}
declare an char array string[10] "Good Luck"
When i assign charPtr = string, I expect an error. However, It
actually runs and outputs:
G
Good Luck
Can someone explain to me how charPtr = string actually works, but if I
create
char string = 'x';
wouldn't work.
#include<math.h>
#include<iostream>
using namespace std;
void main()
{
int value;
value = 500;
char* charPtr;
char string[10] = "Good Luck";
charPtr = string;
cout<< *charPtr<<endl;
cout<<charPtr<<endl;
}