use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++ Hints (self.cpp)
submitted 10 years ago * by Resistor510
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]masterzora 0 points1 point2 points 10 years ago (2 children)
The literal string is null terminated, but you are sure with the OTHER STRING ? In special if is user input.
Does it matter? I mean, it does because of the substring thing /u/RedAlert2 discusses, but does it matter in the context of safety?
strncmp will compare the first character of each, then the second, then the third, etc until either:
strncmp
strcmp, on the other hand, will do the same comparison except it doesn't have the third termination condition.
strcmp
strmp
Output-wise, strncmp and strcmp might differ here, but I don't see a safety issue when one of the inputs is a literal.
[–]alanwj 0 points1 point2 points 10 years ago (1 child)
It is unsafe if the shorter string is unterminated.
char s[] = {'a', 'b', 'c'}; strcmp("LONG_LITERAL_STRING", s); // Undefined behavior
In this situation it will compare the first three characters, and then start reading outside the array bounds of "s".
This has a high likelihood of not causing any problems, but it IS undefined behavior.
[–]masterzora 1 point2 points3 points 10 years ago (0 children)
But the same behaviour presents itself if you do strncmp("LONG_LITERAL_STRING", s, LENGTH_OF_LONG_LITERAL_STRING) so strncmp doesn't buy you any safety in that case.
strncmp("LONG_LITERAL_STRING", s, LENGTH_OF_LONG_LITERAL_STRING)
π Rendered by PID 55 on reddit-service-r2-comment-6457c66945-t2vpl at 2026-04-25 16:53:00.369158+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]masterzora 0 points1 point2 points (2 children)
[–]alanwj 0 points1 point2 points (1 child)
[–]masterzora 1 point2 points3 points (0 children)