char* pointers between C and D
pascal111
judas.the.messiah.111 at gmail.com
Mon Jul 25 09:04:29 UTC 2022
I have small C program that uses a pointer to change the start
address of a string, and when I tried to do the same code but
with D, the D code printed the address of the string after I
increased it one step instead of printing the string the pointer
pointing to. Is there a difference between "char *" pointers
between C and D.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch[]="Hello World!";
char *p;
p=&ch;
p++;
printf("%s\n", p);
return 0;
}
module main;
import std.stdio;
int main(string[] args)
{
char[] ch="Hello World!".dup;
char *p;
p=&ch[0];
p++;
writefln("%s", p);
return 0;
}
More information about the Digitalmars-d-learn
mailing list