| | |
valid or not
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
Hello,
I am no C++ genius, but
++*p++
Cannot be a statement by itself, as there is no ; to finish it.
I am trying to remember if *p is significant. I know that &p is... the address of the variable p. p++ is just an incrementor. But C++ has been a "variable first, then operator" type of language. cars++ people--
I think it is an error.
Christian
I am no C++ genius, but
++*p++
Cannot be a statement by itself, as there is no ; to finish it.
I am trying to remember if *p is significant. I know that &p is... the address of the variable p. p++ is just an incrementor. But C++ has been a "variable first, then operator" type of language. cars++ people--
I think it is an error.
Christian
Increment the object pointed to by p, then increment the pointer p (point to the next object). Really, this code is trivial to come up with on your own. At least give these a try.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main(void) { char text[] = "1b#", *p = text; printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p); ++*p++; printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p); return 0; } /* my output text = "1b#", p(0012FF88) = "1b#", *p = '1' text = "2b#", p(0012FF89) = "b#", *p = 'b' */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
You could say its valid, though it really all depends on how or why its used:
You could ask yourself, "Wow, how'd it come up with 'I'?", though its perfectly understandable. *hello++ is 'H', as the first letter of our string, though ++*hello++ moves our first letter 'H' one to the right, resulting in the next letter of the alphabet, 'I'.
Hope this makes sense,
- Stack Overflow
void pointTo(char **src, char *dst) {
*src = dst;
}
int main() {
char h[25];
char *hello;
pointTo(&hello, h);
strcpy(h, "Hello world!");
printf("%c\n", ++*hello++);
return 0;
}You could ask yourself, "Wow, how'd it come up with 'I'?", though its perfectly understandable. *hello++ is 'H', as the first letter of our string, though ++*hello++ moves our first letter 'H' one to the right, resulting in the next letter of the alphabet, 'I'.
Hope this makes sense,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
![]() |
Similar Threads
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result (PHP)
- Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- mysql_fetch_array(): supplied argument is not a valid MySQL (PHP)
- Valid Html 4.0 (HTML and CSS)
- ADO.NET Specified cast is not valid (ASP.NET)
Other Threads in the C Forum
- Previous Thread: My "if" is not good
- Next Thread: "\x00" problem
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue multi mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






