is this code valid? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

is this code valid?

#include <stdio.h> int main() { printf(6+"hello\0world"); return 0; }

18th Oct 2020, 4:54 AM
Gulpam Doyel
Gulpam Doyel - avatar
3 Answers
+ 6
This is valid code. And it skip first 6 characters in a string. So it prints only "world".
18th Oct 2020, 5:03 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 6
Not very common the use of '\0' in the middle of a string, but it's ok in term that it runs. Valid is a contextual word.
18th Oct 2020, 5:03 AM
Ipang
+ 4
Your code may be valid but if you use that number less than 6 then you will get a warning as you used \0 in the middle of the sentence.
18th Oct 2020, 5:38 AM
The future is now thanks to science
The future is now thanks to science - avatar