strings in C, (i'm newbie in C) -


this question has answer here:

i'm newbie in c language, stupid qeustions, don't know do. trouble:

why code doesn't print nothing?

#include <stdio.h> #include <stdlib.h>   void function(char* valor);  main() { char* valor; int s;      valor=(char*)malloc(101*sizeof(char));     function(valor);     printf("%s\n",valor);  return 0; }  void function(char* valor) {      valor="ciao";  }     

and print string want? ("ciao")

#include <stdio.h> #include <stdlib.h>  main() { char* valor;      valor=(char*)malloc(101*sizeof(char));     valor="ciao";     printf("%s\n",valor);  return 0; } 

the variable valor inside function , variable valor in main different variables.

when change value of valor inside function, nothing happens valor in main.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -