Pointers and access to memory in c. Be careful
Still learning more C and am a little confused. In my references I find cautions about assigning a pointer that has not been initialized. They go on to give examples. Great answers yesterday by the way from folks helping me with pointers, here:
Precedence, Parentheses, Pointers with iterative array functions
On follow up I briefly asked about the last iteration of the loop and potentially pointing the pointer to a non-existent place (i.e. because of my references cautioning against it). So I went back and looked more and find this:
If you have a pointer
int *pt;
then use it without initializing it (i.e. I take this to mean without a statement like *pt= &myVariable
):
*pt = 606;
you could end up with a real bad day depending on where in memory this pointer has been assigned to. The part I'm having trouble with is when working with a string of characters something like this would be ok:
char *str = "Sometimes I feel like I'm going crazy.";
Where the reference says, "Don't worry about where in the memory the string is allocated; it's handled automatically by the compiler". So no need to say initialize *str = &str[0];
or *str = str;
. Meaning, the compiler is automatically char str[n];
in the background?
Why is it that this is handled differently? Or, am I completely misunderstanding?
c pointers
add a comment |
Still learning more C and am a little confused. In my references I find cautions about assigning a pointer that has not been initialized. They go on to give examples. Great answers yesterday by the way from folks helping me with pointers, here:
Precedence, Parentheses, Pointers with iterative array functions
On follow up I briefly asked about the last iteration of the loop and potentially pointing the pointer to a non-existent place (i.e. because of my references cautioning against it). So I went back and looked more and find this:
If you have a pointer
int *pt;
then use it without initializing it (i.e. I take this to mean without a statement like *pt= &myVariable
):
*pt = 606;
you could end up with a real bad day depending on where in memory this pointer has been assigned to. The part I'm having trouble with is when working with a string of characters something like this would be ok:
char *str = "Sometimes I feel like I'm going crazy.";
Where the reference says, "Don't worry about where in the memory the string is allocated; it's handled automatically by the compiler". So no need to say initialize *str = &str[0];
or *str = str;
. Meaning, the compiler is automatically char str[n];
in the background?
Why is it that this is handled differently? Or, am I completely misunderstanding?
c pointers
1
A string in C is a [null-terminated] array of characters. When a literal array is used in an assignment expression context it decays to a pointer to its first element. So,"Sometimes..."
is equivalent to&"Sometimes..."[0]
.
– DYZ
2 hours ago
add a comment |
Still learning more C and am a little confused. In my references I find cautions about assigning a pointer that has not been initialized. They go on to give examples. Great answers yesterday by the way from folks helping me with pointers, here:
Precedence, Parentheses, Pointers with iterative array functions
On follow up I briefly asked about the last iteration of the loop and potentially pointing the pointer to a non-existent place (i.e. because of my references cautioning against it). So I went back and looked more and find this:
If you have a pointer
int *pt;
then use it without initializing it (i.e. I take this to mean without a statement like *pt= &myVariable
):
*pt = 606;
you could end up with a real bad day depending on where in memory this pointer has been assigned to. The part I'm having trouble with is when working with a string of characters something like this would be ok:
char *str = "Sometimes I feel like I'm going crazy.";
Where the reference says, "Don't worry about where in the memory the string is allocated; it's handled automatically by the compiler". So no need to say initialize *str = &str[0];
or *str = str;
. Meaning, the compiler is automatically char str[n];
in the background?
Why is it that this is handled differently? Or, am I completely misunderstanding?
c pointers
Still learning more C and am a little confused. In my references I find cautions about assigning a pointer that has not been initialized. They go on to give examples. Great answers yesterday by the way from folks helping me with pointers, here:
Precedence, Parentheses, Pointers with iterative array functions
On follow up I briefly asked about the last iteration of the loop and potentially pointing the pointer to a non-existent place (i.e. because of my references cautioning against it). So I went back and looked more and find this:
If you have a pointer
int *pt;
then use it without initializing it (i.e. I take this to mean without a statement like *pt= &myVariable
):
*pt = 606;
you could end up with a real bad day depending on where in memory this pointer has been assigned to. The part I'm having trouble with is when working with a string of characters something like this would be ok:
char *str = "Sometimes I feel like I'm going crazy.";
Where the reference says, "Don't worry about where in the memory the string is allocated; it's handled automatically by the compiler". So no need to say initialize *str = &str[0];
or *str = str;
. Meaning, the compiler is automatically char str[n];
in the background?
Why is it that this is handled differently? Or, am I completely misunderstanding?
c pointers
c pointers
edited 5 mins ago
dbush
93.1k12101133
93.1k12101133
asked 2 hours ago
Dan
1239
1239
1
A string in C is a [null-terminated] array of characters. When a literal array is used in an assignment expression context it decays to a pointer to its first element. So,"Sometimes..."
is equivalent to&"Sometimes..."[0]
.
– DYZ
2 hours ago
add a comment |
1
A string in C is a [null-terminated] array of characters. When a literal array is used in an assignment expression context it decays to a pointer to its first element. So,"Sometimes..."
is equivalent to&"Sometimes..."[0]
.
– DYZ
2 hours ago
1
1
A string in C is a [null-terminated] array of characters. When a literal array is used in an assignment expression context it decays to a pointer to its first element. So,
"Sometimes..."
is equivalent to &"Sometimes..."[0]
.– DYZ
2 hours ago
A string in C is a [null-terminated] array of characters. When a literal array is used in an assignment expression context it decays to a pointer to its first element. So,
"Sometimes..."
is equivalent to &"Sometimes..."[0]
.– DYZ
2 hours ago
add a comment |
4 Answers
4
active
oldest
votes
In this case:
char *str = "Sometimes I feel like I'm going crazy.";
You're initializing str
to contain the address of the given string literal. You're not actually dereferencing anything at this point.
This is also fine:
char *str;
str = "Sometimes I feel like I'm going crazy.";
Because you're assigning to str
and not actually dereferencing it.
This is a problem:
int *pt;
*pt = 606;
Because pt
is not initialized and then it is dereferenced.
You also can't do this for the same reason (plus the types don't match):
*pt= &myVariable;
But you can do this:
pt= &myVariable;
After which you can freely use *pt
.
1
I take what you've written to mean:char *str = "Sometimes I feel like I'm going crazy.";
does not =char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
1
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
add a comment |
When you write sometype *p = something;
, it's equivalent to sometype *p; p = something;
, not sometype *p; *p = something;
. That means when you use a string literal like that, the compiler figures out where to put it and then puts its address there.
The statement
char *str = "Sometimes I feel like I'm going crazy.";
is equivalent to
char *str;
str = "Sometimes I feel like I'm going crazy.";
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
add a comment |
Simplifying the string literal can be expressed as:
const char literal = "Sometimes I feel like I'm going crazy."
so the expression
char *str = "Sometimes I feel like I'm going crazy.";
is logically equivalent to:
const char literal = "Sometimes I feel like I'm going crazy."
char *str = literal;
of course literals do not have the names
But you can't deference the char pointer which does not have allocated memory for the actual object
/* Wrong */
char *c;
*c = 'a';
/* Wrong - you assign the pointer with the integer value */
char *d = 'a';
/* Correct */
char *d = malloc(1);
*d = 'a';
/* Correct */
char x
char *e = &x;
*e = 'b';
The last example.
/* Wrong - you assign the pointer with the integer value */
int *p = 666;
/* Wrong oyu dereference the pointer which references to the not allocated space */
int *r;
*r = 666;
/* Correct */
int *s = malloc(sizeof(*s));
*s = 666;
/* Correct */
int t;
int *u = &t;
*u = 666;
And the last one - something similar to the string literals = the compound literals
/* Correct */
int *z = (int){666,567,234};
z[2] = 0;
*z = 5;
/* Correct */
int *z = (const int){666,567,234};
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
add a comment |
Doing char *str = "I am a string"; means declaring and initializing an array of char. There's no problem since you're giving all the content of the array in the declaration.
Doing int *pt = 606; is the same as doing char *str = 'a'; there's a problem: you're not giving enough information while declaring your variable.
You need to do int nb = 606; int *pt = &nb; this way you give you pointer the address of the variable. Or if you want: you pass the int as an array of int.
1
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025987%2fpointers-and-access-to-memory-in-c-be-careful%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
In this case:
char *str = "Sometimes I feel like I'm going crazy.";
You're initializing str
to contain the address of the given string literal. You're not actually dereferencing anything at this point.
This is also fine:
char *str;
str = "Sometimes I feel like I'm going crazy.";
Because you're assigning to str
and not actually dereferencing it.
This is a problem:
int *pt;
*pt = 606;
Because pt
is not initialized and then it is dereferenced.
You also can't do this for the same reason (plus the types don't match):
*pt= &myVariable;
But you can do this:
pt= &myVariable;
After which you can freely use *pt
.
1
I take what you've written to mean:char *str = "Sometimes I feel like I'm going crazy.";
does not =char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
1
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
add a comment |
In this case:
char *str = "Sometimes I feel like I'm going crazy.";
You're initializing str
to contain the address of the given string literal. You're not actually dereferencing anything at this point.
This is also fine:
char *str;
str = "Sometimes I feel like I'm going crazy.";
Because you're assigning to str
and not actually dereferencing it.
This is a problem:
int *pt;
*pt = 606;
Because pt
is not initialized and then it is dereferenced.
You also can't do this for the same reason (plus the types don't match):
*pt= &myVariable;
But you can do this:
pt= &myVariable;
After which you can freely use *pt
.
1
I take what you've written to mean:char *str = "Sometimes I feel like I'm going crazy.";
does not =char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
1
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
add a comment |
In this case:
char *str = "Sometimes I feel like I'm going crazy.";
You're initializing str
to contain the address of the given string literal. You're not actually dereferencing anything at this point.
This is also fine:
char *str;
str = "Sometimes I feel like I'm going crazy.";
Because you're assigning to str
and not actually dereferencing it.
This is a problem:
int *pt;
*pt = 606;
Because pt
is not initialized and then it is dereferenced.
You also can't do this for the same reason (plus the types don't match):
*pt= &myVariable;
But you can do this:
pt= &myVariable;
After which you can freely use *pt
.
In this case:
char *str = "Sometimes I feel like I'm going crazy.";
You're initializing str
to contain the address of the given string literal. You're not actually dereferencing anything at this point.
This is also fine:
char *str;
str = "Sometimes I feel like I'm going crazy.";
Because you're assigning to str
and not actually dereferencing it.
This is a problem:
int *pt;
*pt = 606;
Because pt
is not initialized and then it is dereferenced.
You also can't do this for the same reason (plus the types don't match):
*pt= &myVariable;
But you can do this:
pt= &myVariable;
After which you can freely use *pt
.
edited 2 hours ago
answered 2 hours ago
dbush
93.1k12101133
93.1k12101133
1
I take what you've written to mean:char *str = "Sometimes I feel like I'm going crazy.";
does not =char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
1
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
add a comment |
1
I take what you've written to mean:char *str = "Sometimes I feel like I'm going crazy.";
does not =char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
1
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
1
1
I take what you've written to mean:
char *str = "Sometimes I feel like I'm going crazy.";
does not = char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
I take what you've written to mean:
char *str = "Sometimes I feel like I'm going crazy.";
does not = char *str;
*str = "Sometimes I feel like I'm going crazy.";
– Dan
2 hours ago
1
1
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
@Dan Correct. In the former case you initialize the pointer, in the latter case you dereference it.
– dbush
2 hours ago
add a comment |
When you write sometype *p = something;
, it's equivalent to sometype *p; p = something;
, not sometype *p; *p = something;
. That means when you use a string literal like that, the compiler figures out where to put it and then puts its address there.
The statement
char *str = "Sometimes I feel like I'm going crazy.";
is equivalent to
char *str;
str = "Sometimes I feel like I'm going crazy.";
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
add a comment |
When you write sometype *p = something;
, it's equivalent to sometype *p; p = something;
, not sometype *p; *p = something;
. That means when you use a string literal like that, the compiler figures out where to put it and then puts its address there.
The statement
char *str = "Sometimes I feel like I'm going crazy.";
is equivalent to
char *str;
str = "Sometimes I feel like I'm going crazy.";
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
add a comment |
When you write sometype *p = something;
, it's equivalent to sometype *p; p = something;
, not sometype *p; *p = something;
. That means when you use a string literal like that, the compiler figures out where to put it and then puts its address there.
The statement
char *str = "Sometimes I feel like I'm going crazy.";
is equivalent to
char *str;
str = "Sometimes I feel like I'm going crazy.";
When you write sometype *p = something;
, it's equivalent to sometype *p; p = something;
, not sometype *p; *p = something;
. That means when you use a string literal like that, the compiler figures out where to put it and then puts its address there.
The statement
char *str = "Sometimes I feel like I'm going crazy.";
is equivalent to
char *str;
str = "Sometimes I feel like I'm going crazy.";
edited 2 hours ago
Richard Chambers
9,56024066
9,56024066
answered 2 hours ago
Joseph Sible
5,0602930
5,0602930
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
add a comment |
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
Thank you so much. both answers have helped my understanding greatly!
– Dan
2 hours ago
add a comment |
Simplifying the string literal can be expressed as:
const char literal = "Sometimes I feel like I'm going crazy."
so the expression
char *str = "Sometimes I feel like I'm going crazy.";
is logically equivalent to:
const char literal = "Sometimes I feel like I'm going crazy."
char *str = literal;
of course literals do not have the names
But you can't deference the char pointer which does not have allocated memory for the actual object
/* Wrong */
char *c;
*c = 'a';
/* Wrong - you assign the pointer with the integer value */
char *d = 'a';
/* Correct */
char *d = malloc(1);
*d = 'a';
/* Correct */
char x
char *e = &x;
*e = 'b';
The last example.
/* Wrong - you assign the pointer with the integer value */
int *p = 666;
/* Wrong oyu dereference the pointer which references to the not allocated space */
int *r;
*r = 666;
/* Correct */
int *s = malloc(sizeof(*s));
*s = 666;
/* Correct */
int t;
int *u = &t;
*u = 666;
And the last one - something similar to the string literals = the compound literals
/* Correct */
int *z = (int){666,567,234};
z[2] = 0;
*z = 5;
/* Correct */
int *z = (const int){666,567,234};
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
add a comment |
Simplifying the string literal can be expressed as:
const char literal = "Sometimes I feel like I'm going crazy."
so the expression
char *str = "Sometimes I feel like I'm going crazy.";
is logically equivalent to:
const char literal = "Sometimes I feel like I'm going crazy."
char *str = literal;
of course literals do not have the names
But you can't deference the char pointer which does not have allocated memory for the actual object
/* Wrong */
char *c;
*c = 'a';
/* Wrong - you assign the pointer with the integer value */
char *d = 'a';
/* Correct */
char *d = malloc(1);
*d = 'a';
/* Correct */
char x
char *e = &x;
*e = 'b';
The last example.
/* Wrong - you assign the pointer with the integer value */
int *p = 666;
/* Wrong oyu dereference the pointer which references to the not allocated space */
int *r;
*r = 666;
/* Correct */
int *s = malloc(sizeof(*s));
*s = 666;
/* Correct */
int t;
int *u = &t;
*u = 666;
And the last one - something similar to the string literals = the compound literals
/* Correct */
int *z = (int){666,567,234};
z[2] = 0;
*z = 5;
/* Correct */
int *z = (const int){666,567,234};
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
add a comment |
Simplifying the string literal can be expressed as:
const char literal = "Sometimes I feel like I'm going crazy."
so the expression
char *str = "Sometimes I feel like I'm going crazy.";
is logically equivalent to:
const char literal = "Sometimes I feel like I'm going crazy."
char *str = literal;
of course literals do not have the names
But you can't deference the char pointer which does not have allocated memory for the actual object
/* Wrong */
char *c;
*c = 'a';
/* Wrong - you assign the pointer with the integer value */
char *d = 'a';
/* Correct */
char *d = malloc(1);
*d = 'a';
/* Correct */
char x
char *e = &x;
*e = 'b';
The last example.
/* Wrong - you assign the pointer with the integer value */
int *p = 666;
/* Wrong oyu dereference the pointer which references to the not allocated space */
int *r;
*r = 666;
/* Correct */
int *s = malloc(sizeof(*s));
*s = 666;
/* Correct */
int t;
int *u = &t;
*u = 666;
And the last one - something similar to the string literals = the compound literals
/* Correct */
int *z = (int){666,567,234};
z[2] = 0;
*z = 5;
/* Correct */
int *z = (const int){666,567,234};
Simplifying the string literal can be expressed as:
const char literal = "Sometimes I feel like I'm going crazy."
so the expression
char *str = "Sometimes I feel like I'm going crazy.";
is logically equivalent to:
const char literal = "Sometimes I feel like I'm going crazy."
char *str = literal;
of course literals do not have the names
But you can't deference the char pointer which does not have allocated memory for the actual object
/* Wrong */
char *c;
*c = 'a';
/* Wrong - you assign the pointer with the integer value */
char *d = 'a';
/* Correct */
char *d = malloc(1);
*d = 'a';
/* Correct */
char x
char *e = &x;
*e = 'b';
The last example.
/* Wrong - you assign the pointer with the integer value */
int *p = 666;
/* Wrong oyu dereference the pointer which references to the not allocated space */
int *r;
*r = 666;
/* Correct */
int *s = malloc(sizeof(*s));
*s = 666;
/* Correct */
int t;
int *u = &t;
*u = 666;
And the last one - something similar to the string literals = the compound literals
/* Correct */
int *z = (int){666,567,234};
z[2] = 0;
*z = 5;
/* Correct */
int *z = (const int){666,567,234};
edited 2 hours ago
answered 2 hours ago
P__J__
8,9762723
8,9762723
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
add a comment |
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
Thank you @P_J_ this helps me also! I appreciate it!
– Dan
38 mins ago
add a comment |
Doing char *str = "I am a string"; means declaring and initializing an array of char. There's no problem since you're giving all the content of the array in the declaration.
Doing int *pt = 606; is the same as doing char *str = 'a'; there's a problem: you're not giving enough information while declaring your variable.
You need to do int nb = 606; int *pt = &nb; this way you give you pointer the address of the variable. Or if you want: you pass the int as an array of int.
1
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
add a comment |
Doing char *str = "I am a string"; means declaring and initializing an array of char. There's no problem since you're giving all the content of the array in the declaration.
Doing int *pt = 606; is the same as doing char *str = 'a'; there's a problem: you're not giving enough information while declaring your variable.
You need to do int nb = 606; int *pt = &nb; this way you give you pointer the address of the variable. Or if you want: you pass the int as an array of int.
1
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
add a comment |
Doing char *str = "I am a string"; means declaring and initializing an array of char. There's no problem since you're giving all the content of the array in the declaration.
Doing int *pt = 606; is the same as doing char *str = 'a'; there's a problem: you're not giving enough information while declaring your variable.
You need to do int nb = 606; int *pt = &nb; this way you give you pointer the address of the variable. Or if you want: you pass the int as an array of int.
Doing char *str = "I am a string"; means declaring and initializing an array of char. There's no problem since you're giving all the content of the array in the declaration.
Doing int *pt = 606; is the same as doing char *str = 'a'; there's a problem: you're not giving enough information while declaring your variable.
You need to do int nb = 606; int *pt = &nb; this way you give you pointer the address of the variable. Or if you want: you pass the int as an array of int.
answered 2 hours ago
Mathieu Gasciolli
113
113
1
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
add a comment |
1
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
1
1
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
There are a number of inaccuracies in this posting nor does it really answer the OP's question.
– Richard Chambers
2 hours ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025987%2fpointers-and-access-to-memory-in-c-be-careful%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
A string in C is a [null-terminated] array of characters. When a literal array is used in an assignment expression context it decays to a pointer to its first element. So,
"Sometimes..."
is equivalent to&"Sometimes..."[0]
.– DYZ
2 hours ago