This is my code. I want to know what is happening here. Can anybody describe the code? char *string;   string = &quot;Le Casa de Papel&quot;;       *(str+1) = 'a';   return 0;
924
The following code receives seg fault on line 2:  char *str = "string"; str[0] = 'z';  // could be also written as *str = 'z' printf("%s\n", str);   While this works perfectly well:  char str[] = "string"; str[0] = 'z'; printf("%s\n", str);   Tested with MSVC and GCC.
35663
My controller code is as follows -          for(String resStr : responseArray){             if(resStr.indexOf('r_error_str') != -1){                 responseString += resStr.substring(resStr.indexOf('=') + 1);                  responseString += '\n';             }         }   but when i display this 'responseString ' String using 'apex:outputLabel or apex:outputText or as Exception message '\n' is not converting in new line. Whole String is coming in one line.  Can anyone explain why is this happining
20025
Possible Duplicate:          How do you convert a C++ string to an int?  Assume you are expecting the string to have actual numbers in it ("1", "345", "38944", for example).  Also, let's assume you don't have boost, and you really want to do it the C++ way, not the crufty old C way.
63970
Possible Duplicate:          I want to write a function that reverses the given string passed into it. But, I can not. If I supply the doReverse function (see code below) with a character array, my code works well.  I can't figure out why this does not work. I am able to access str[0] in doReverse, but I can't change any value of the array by using a char pointer. Any ideas?  void doReverse(char *str) {     str[0] = 'b'; }  void main(void) {     char *str = "abc";     doReverse(str);     puts(str); }   Update:  I know how to do write a reverse function by passing a character array to it:  void reverse1(char p[]) {     int i, temp, y;      for (i = 0, y = strlen(p); i &lt; y; ++i, --y) {         temp = p[y-1];         p[y-1] = p[i];         p[i] = temp;     } }   But, I want to write another version that gets a char pointer as a parameter.
203
I came across this code:  void f(const std::string &amp;s);   And then a call:  f( *((std::string*)NULL) );   And I was wondering what others think of this construction, it is used to signal that function f() should use some default value (which it computes) instead of some user provided value.  I am not sure what to think of it, it looks weird but what do you think of this construction?
44888
I'm reading The C++ Programming Language and in it Stroustrup states that the int value of a char can range from 0 to 255 or -127 to 127, depending on implementation. Is this correct? It seems like it should be from -128 to 127.  If not, why are their only 255 possible values in the second implementation possibility, not 256.
44048
I'm working on a C-brain teaser:  Write the standard Hello-World program, without semi-colons.  My best answer so far is:  int main(void) {     if (printf("Hello World!\n"), exit(0), 0)     {         /* do nothing */     } }   But I don't understand why I don't get compiler error (Visual Studio):  error C4716: 'main' : must return a value   I've tried other functions with a return-type declared, but missing a return-statement, and get this compiler error.    Note that I've also tried:  int foo(void) {     if (printf("Hello World!\n"), exit(0), true)     {         /* do nothing */     } }  int main(void) {     foo(); }   And don't get a compiler error on foo.  If I remove the "exit(0)", I do get the compiler error.  Apparently the compiler has knowledge that "exit" is a special function?  This seems very odd to me.
54729
I'm looking for a way to convert a preprocessor token to a string.  Specifically, I've somewhere got:  #define MAX_LEN 16   and I want to use it to prevent buffer overrun:  char val[MAX_LEN+1]; // room for \0 sscanf(buf, "%"MAX_LEN"s", val);   I'm open to other ways to accomplish the same thing, but standard library only.
7720
In C++, sizeof('a') == sizeof(char) == 1. This makes intuitive sense, since 'a' is a character literal, and sizeof(char) == 1 as defined by the standard.  In C however, sizeof('a') == sizeof(int). That is, it appears that C character literals are actually integers. Does anyone know why? I can find plenty of mentions of this C quirk but no explanation for why it exists.
33306
Hey! I was looking at this code at   I noticed that in some situations they used hex numbers, like in line 134:  for (j = 1; val &amp;&amp; j &lt;= 0x80; j &lt;&lt;= 1, q++)   Now why would they use the 0x80? I am not that good with hex but I found an online hex to decimal and it gave me 128 for 0x80.  Also before line 134, on line 114 they have this:  small_n = (n &amp; 0xffff0000) == 0;   The hex to decimal gave me 4294901760 for that hex number. So here in this line they are making a bit AND and comparing the result to 0??  Why not just use the number? Can anyone please explain and please do give examples of other situations.  Also I have seen large lines of code where it's just hex numbers and never really understood why :(
271
How do you left pad an int with zeros when converting to a String in java?  I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).
114561
Could I get an example as to how these three elements (are these called metacharacters?) differ?  I know that * means all or nothing, but I am not sure if it's the right way to think about it. On the other hand . and ? seem the same. They match one character, right?
49393
I'm working with some code that widely uses the idiom of returning a pointer to a static local variable.  eg:  char* const GetString() {   static char sTest[5];   strcpy(sTest, "Test");   return sTest; }   Am I right in thinking that this is safe?  PS, I know that this would be a better way of doing the same thing:  char* const GetString() {   return "Test"; }   Edit: Apologies, the function signature should of course be:  const char* GetString();
114980
See:   In many C flavoured languages, and some older languages like Fortran, one can use Pointers. As someone who has only really programmed in basic, javascript, and actionscript, can you explain to me what a Pointer is, and what it is most useful for? Thanks!
106126
I was debugging something and discovered some strangeness in JavaScript:  alert(1=='') ==&gt; false alert(0=='') ==&gt; true alert(-1=='') ==&gt; false   It would make sense that an implied string comparison that 0 should = '0'. This is true for all non-zero values, but why not for zero?
64766
When I make a call to the C string compare function like this:  strcmp("time","time")  It returns 0, which implies that the strings are not equal.  Can anyone tell me why C implementations seem to do this? I would think it would return a non-zero value if equal. I am curious to the reasons I am seeing this behavior.
25904
As a follow-up to :  From what I've seen, this should work as expected:  void greet(){   char c[] = "Hello";   greetWith(c);   return; }   but this will cause undefined behavior:  char *greet(){    char c[] = "Hello";   return c; }   If I'm right, what's the best way to fix the second greet function? In an embedded environment? On a desktop?