| | |
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 |
#include * ansi array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list lists locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation overwrite owf pdf pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






