1. How do you declare a variable s containing the string hello?
My attempt:
char s = "hello";
2. Why is it that when the following code executes:
int i = -1;
int k = i++;
k is -1, isn't k 0?
Thank you!
This is a discussion on 2 simple C program questions. within the C Programming forums, part of the General Programming Boards category; 1. How do you declare a variable s containing the string hello? My attempt: char s = "hello"; 2. Why ...
1. How do you declare a variable s containing the string hello?
My attempt:
char s = "hello";
2. Why is it that when the following code executes:
int i = -1;
int k = i++;
k is -1, isn't k 0?
Thank you!
Both of these questions should be easy to answer after having read some introductory material on C, so re-read your book/notes on strings and on post-increment.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Okay I found out the first one is chars[] = "hello";
But for the second question I cannot find it in my notes :S.
I was thinking that i++ only works when it is on it's own, ex:
int i = -1;
i++;
int k = i;
With the space you had before, yesOriginally Posted by justiliang
If you cannot find "post-increment", then just try "increment", or look back to where the operator was introduced to you. You might also recall pre-incement, e.g., ++i. The crux of this question is how does i++ differ from ++iOriginally Posted by justiliang
![]()
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
OOOO, yeah I found increment.
So i++ is a postfix position and it looks like
int k = i++;
is the same as
int k = i;
i = i + 1;
?
Thanks for the help![]()
For the purposes of this discussion, yes, you have the right idea.Originally Posted by justiliang
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way