Char* c= "Hello World"

char* c= "Hello World"
>compiles
int* i= 4
>invalid conversion from int to int*

Attached: epic-face_fb_232179.jpg (300x300, 11K)

Brainlet of the year.

ITT: proof that you can use the Internet with

How the fuck do you even know how to compile.

i don't understand. is "Hello World" a pointer?

the compiler reserves space for each character, and stores the address of the first character to c

No, it resolves to an address of type char *.
c is a pointer, and stores the address of the string "Hello World"

char* c= "Hello World";
Is just syntax sugar for
char c[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'};

Actually
char c[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '\0'};

why can't you assign an arbitrary value to a pointer and access that memory address?

>char* c= "Hello World" compiles
Were you expecting it to not compile for some reason?

Not true. sizeof(c) in first instance is sizeof(char*), in the second instance it is 12.

The stored data is the same, only the variable type is different.

another example of why C's syntax is shit.
still a good language though

and the storage location and mutability of the data is different. First example is stored in readonly memory, second example is stored on the stack

Threads like this make me feel so more secure in my ability when people like this exist

You can. It just causes problems. Might be a segfault/illegal operation and the OS will kill your program, or if you are within the memory space you are permitted to access, then changing values arbitrarily will just make your program 'misbehave'.

>why can't you assign an arbitrary value to a pointer and access that memory address?
why can't you assign an arbitrary value to a pointer and access that memory address?

you can
((unsigned char*)0) + yourInt

>It's another retard who doesn't know how to use a language is complaining about said language thread
Blessed day

>why can't you assign an arbitrary value to a pointer and access that memory address?
You can, all you fucking like, it's why people call C "unsafe"

No it's not.
First of all, sizeof(c) differs between these. But more importantly modifying the string in the first case is undefined behavior and should be declared as const char* instead

because of Poe's law, I do not even know if its bait or legitimate room temperature IQ

brainlet OP here. after reading your replies I made this interesting program that helped solidify my understanding. if prints the addresses with the null termination and overflows the array to show you random memory. so thanks guys

#include

using namespace std;

int main(){

//notice the size of a character in bytes//

cout

now I know you all may be asking yourselves, what's so interesting about this code...

well it's the fact that if p is an integer pointer, and i is an integer array, you don't need to use the address of operator to get the address when it's fed into cout.

while p is a character pointer, cout will read the remainder of the string, if there is no & before the p.

sample output:


Character Size: 1 bytes

0x7ffd9264d000 : a

abcdefghij : a
bcdefghij : b
cdefghij : c
defghij : d
efghij : e
fghij : f
ghij : g
hij : h
ij : i
j : j
:
�~�������oU :
�~�������oU : �
~�������oU : ~
�������oU : �
������oU : �
�����oU : �
����oU : �
���oU : �
��oU : �