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

C / C++ / MFC

 
QuestionControlling bass and treble on an audio device Pin
dptalt8-Jun-09 4:18
dptalt8-Jun-09 4:18 
QuestionUsed cluster number of a hard disk partition come continuously...Is it correct..? Pin
krish_kumar8-Jun-09 4:08
krish_kumar8-Jun-09 4:08 
QuestionHlep me!A problem of AttachDispatch method~ Pin
bjwu8-Jun-09 2:42
bjwu8-Jun-09 2:42 
Questionpassing pointers to function Pin
hrishiS8-Jun-09 2:26
hrishiS8-Jun-09 2:26 
AnswerRe: passing pointers to function Pin
«_Superman_»8-Jun-09 2:40
professional«_Superman_»8-Jun-09 2:40 
GeneralRe: passing pointers to function Pin
Stuart Dootson8-Jun-09 2:43
professionalStuart Dootson8-Jun-09 2:43 
GeneralRe: passing pointers to function Pin
«_Superman_»8-Jun-09 2:53
professional«_Superman_»8-Jun-09 2:53 
GeneralRe: passing pointers to function Pin
Stuart Dootson8-Jun-09 3:22
professionalStuart Dootson8-Jun-09 3:22 
Sorry for being abrupt - I'm in a bit of a sh1t mood today Sigh | :sigh: .

«_Superman_» wrote:
What I believe is that declaring char* ptr = "abc" is exactly the same as const char* ptr = "abc".


Mmmm - not quite. As far as the compiler's concerned, ptr is a char* - that's how you've declared it, the compiler trusts you. It will allow you to write to the contents of ptr. However, the underlying memory that ptr refers to (the string literal) is in read-only memory, so a combination of the compiler, linker and program loader (htat's what makes the string literal memory read-only, IIRC) has broken type-safety, by allowing you to assign a (const char*) pointer value to a (char *) pointer variable.

«_Superman_» wrote:
And also when i tried what the OP says it didn't change the value even when giving "ggg".


As I said in my response to the OP, he is passing a pointer value to fun. You can change that pointer (as he does) in the function, but it's no different than (say) changing an integer parameter that you pass in. What you can do with a pointer is to change the thing that it points at:

fun(char* str)
{
   str[0] = 'A';
}


However, as the original pointer references a string literal (which is in read-only memory, remember), this will accvio, as you're writing to read-only memory, and the processor's MMU ain't gonna let ya do that.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: passing pointers to function Pin
«_Superman_»8-Jun-09 3:40
professional«_Superman_»8-Jun-09 3:40 
GeneralRe: passing pointers to function Pin
Stuart Dootson8-Jun-09 3:43
professionalStuart Dootson8-Jun-09 3:43 
GeneralRe: passing pointers to function Pin
«_Superman_»8-Jun-09 3:48
professional«_Superman_»8-Jun-09 3:48 
GeneralRe: passing pointers to function Pin
hrishiS9-Jun-09 0:34
hrishiS9-Jun-09 0:34 
AnswerRe: passing pointers to function Pin
Stuart Dootson8-Jun-09 2:50
professionalStuart Dootson8-Jun-09 2:50 
GeneralRe: passing pointers to function Pin
hrishiS9-Jun-09 0:35
hrishiS9-Jun-09 0:35 
GeneralRe: passing pointers to function Pin
David Crow8-Jun-09 3:16
David Crow8-Jun-09 3:16 
GeneralRe: passing pointers to function Pin
Rajesh R Subramanian8-Jun-09 3:28
professionalRajesh R Subramanian8-Jun-09 3:28 
AnswerRe: passing pointers to function Pin
CPallini8-Jun-09 3:26
mveCPallini8-Jun-09 3:26 
Questionhindi character pattern recognition [modified] Pin
Member 62745948-Jun-09 0:41
Member 62745948-Jun-09 0:41 
AnswerRe: hindi character pattern recognition Pin
Chandrasekharan P8-Jun-09 1:07
Chandrasekharan P8-Jun-09 1:07 
AnswerRe: hindi character pattern recognition Pin
Chandrasekharan P8-Jun-09 1:49
Chandrasekharan P8-Jun-09 1:49 
AnswerRe: hindi character pattern recognition Pin
Alan Balkany8-Jun-09 4:18
Alan Balkany8-Jun-09 4:18 
Questioncode for recognising character pattern in vc++ Pin
prerananit8-Jun-09 0:17
prerananit8-Jun-09 0:17 
AnswerRe: code for recognising character pattern in vc++ Pin
CPallini8-Jun-09 0:20
mveCPallini8-Jun-09 0:20 
AnswerRe: code for recognising character pattern in vc++ Pin
Chandrasekharan P8-Jun-09 0:22
Chandrasekharan P8-Jun-09 0:22 
AnswerRe: code for recognising character pattern in vc++ Pin
Rajesh R Subramanian8-Jun-09 0:30
professionalRajesh R Subramanian8-Jun-09 0:30 

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.