Click here to Skip to main content
15,887,267 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC small help please Pin
_Flaviu23-Jun-14 22:10
_Flaviu23-Jun-14 22:10 
Questioncan be p[-1] dereferenced? Pin
sakthimuhuu22-Jun-14 18:54
sakthimuhuu22-Jun-14 18:54 
AnswerRe: can be p[-1] dereferenced? Pin
«_Superman_»22-Jun-14 20:22
professional«_Superman_»22-Jun-14 20:22 
AnswerRe: can be p[-1] dereferenced? Pin
Jochen Arndt22-Jun-14 21:00
professionalJochen Arndt22-Jun-14 21:00 
AnswerRe: can be p[-1] dereferenced? Pin
CPallini22-Jun-14 22:16
mveCPallini22-Jun-14 22:16 
GeneralRe: can be p[-1] dereferenced? Pin
sakthimuhuu24-Jun-14 2:11
sakthimuhuu24-Jun-14 2:11 
QuestionRe: can be p[-1] dereferenced? Pin
CPallini24-Jun-14 2:21
mveCPallini24-Jun-14 2:21 
AnswerRe: can be p[-1] dereferenced? Pin
Satya Chamakuri12-Aug-14 21:38
Satya Chamakuri12-Aug-14 21:38 
Hi,

int main()
{
char *p = "Test";
p++;
p++;
printf("%s", p[-1]);
getchar();
return 0;
}

Suppose think the starting address of p will be 0x20000,
You are incrementing p two times, so before entering to the highlighted line in above code value of p is 0x20002 and the content in that location as starting address will be st.

Then p[-1] means *(p-1), means value at 0x20001 location. means 'e'.

In printf, %s is a format specifier wich will try to display the string at the memory location provided in variable list. Here the address provided in variable list is value of *(p-1), i.e, 'e' (internally this is 0x65). So %s dereferences the value at 0x65, so some garbage value it will print finally. otherwise will terminate the program as memory is un referenced.

Thanks
QuestionDirectShow not showing mp4 & WndProc Not working Pin
AmbiguousName20-Jun-14 1:23
AmbiguousName20-Jun-14 1:23 
AnswerRe: Can not Get Notification using WndProc Pin
Richard MacCutchan20-Jun-14 1:30
mveRichard MacCutchan20-Jun-14 1:30 
GeneralRe: Can not Get Notification using WndProc Pin
AmbiguousName20-Jun-14 2:04
AmbiguousName20-Jun-14 2:04 
GeneralRe: Can not Get Notification using WndProc Pin
Richard MacCutchan20-Jun-14 2:11
mveRichard MacCutchan20-Jun-14 2:11 
Questionswprintf_s with *wstring (Resolved) Pin
bkelly1319-Jun-14 6:39
bkelly1319-Jun-14 6:39 
QuestionRe: swprintf_s with *wstring Pin
David Crow19-Jun-14 6:54
David Crow19-Jun-14 6:54 
AnswerRe: swprintf_s with *wstring Pin
bkelly1319-Jun-14 7:11
bkelly1319-Jun-14 7:11 
QuestionRe: swprintf_s with *wstring Pin
David Crow19-Jun-14 9:53
David Crow19-Jun-14 9:53 
AnswerRe: swprintf_s with *wstring Pin
Graham Breach19-Jun-14 7:09
Graham Breach19-Jun-14 7:09 
GeneralRe: swprintf_s with *wstring Pin
bkelly1319-Jun-14 7:21
bkelly1319-Jun-14 7:21 
GeneralRe: swprintf_s with *wstring Pin
Richard MacCutchan19-Jun-14 23:28
mveRichard MacCutchan19-Jun-14 23:28 
QuestionCould not get the ConnectionString from Registry Key Pin
Member 1089437819-Jun-14 0:04
Member 1089437819-Jun-14 0:04 
SuggestionRe: Could not get the ConnectionString from Registry Key Pin
Richard MacCutchan19-Jun-14 0:35
mveRichard MacCutchan19-Jun-14 0:35 
GeneralRe: Could not get the ConnectionString from Registry Key Pin
Member 1089437819-Jun-14 22:42
Member 1089437819-Jun-14 22:42 
GeneralRe: Could not get the ConnectionString from Registry Key Pin
Richard MacCutchan19-Jun-14 23:26
mveRichard MacCutchan19-Jun-14 23:26 
GeneralRe: Could not get the ConnectionString from Registry Key Pin
Member 1089437820-Jun-14 4:00
Member 1089437820-Jun-14 4:00 
GeneralRe: Could not get the ConnectionString from Registry Key Pin
Richard MacCutchan20-Jun-14 4:08
mveRichard MacCutchan20-Jun-14 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.