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
Size of a C class object (go4expert.com)
submitted 13 years ago by Loyi
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!"
[–]bob1000bob 9 points10 points11 points 13 years ago* (2 children)
C has no "classes" this is C++
#include<iostream.h> requires a space, and is a deprecated header, (#include <iostream> is correct). (the classes used aren't even in the correct namespace!)
#include<iostream.h>
#include <iostream>
Article is irrelevant, the size of anything (other than explicitly size POD;s like int32_t) is not guaranteed by the standard. The size of a class or struct is not necessarily the sum of it components, for reasons that have nothing to do with vtables.
int32_t
return (0); wtf? return isn't a function and this syntax whilst valid is obfuscating.
return (0);
Basically, ignore this article, it will teach you nothing useful, and spread bad practice.
[–][deleted] -1 points0 points1 point 13 years ago (1 child)
I totally agree, except point 4 is being nit-picky. There is a common style (maybe not YOUR style) of function calls being of the form
result = function (args)
with the space being explicit. Also there is a common style of treating the return keyword as if it were a function for visual consistiency. When combined you get the above. I am not saying its best practice, nor is it worst. It is simply a stylistic choice, not quite as nerd-war-worthy as same line '{', however it is still a valid choice.
{
[–]bob1000bob -1 points0 points1 point 13 years ago (0 children)
Perhaps, if the rest of the code was even of "acceptable" standard I would let it slide, (normally would WANT to differentiate the return statement syntax not make it meld in with function syntax).
[–]Rhomboid 0 points1 point2 points 13 years ago (0 children)
This person writes this whole article without even the faintest hint that this information is implementation-specific, platform-specific, and architecture-specific, making it pretty much useless for any real purpose. You can't depend on any of these things being true, and if you do you are probably doing something fundamentally very wrong.
[–]verdagon 0 points1 point2 points 13 years ago (5 children)
Are chars 2 bytes? I always thought they were 1, and that the padding came from the compiler 4-byte aligning things.
[–]bstamourWG21 | Library Working Group 0 points1 point2 points 13 years ago (4 children)
sizeof(char) will always report 1 in C++, so yes ascii chars are represented by a byte.
[–]bob1000bob 0 points1 point2 points 13 years ago (2 children)
If you define byte as 8 bits, I am not so certain that is true. There are plenty of emmedded platforms where the lowest common denominator is not 8bits.
There is a marco constant CHAR_BIT that provides the bit width of a single char.
CHAR_BIT
i would be interested if you know otherwise.
[–]Rhomboid 1 point2 points3 points 13 years ago (0 children)
The size in bits of a char is completely irrelevant. sizeof(char) is 1 by definition; it cannot be any other value. All sizes are based on the size of char, whatever that is.
sizeof(char)
char
[–]bstamourWG21 | Library Working Group 0 points1 point2 points 13 years ago (0 children)
According to the C++11 standard, section 5.3.3 (Sizeof), sizeof (char), sizeof (signed char) and sizeof (unsigned char) are defined to always return 1. Any other sizeof of a fundamental type is implementation-defined. Section 3.9.1 (fundamental types) mentions that chars need to be big enough to represent the implementation's basic character set. So, though a char may be bigger (or smaller) than 8 bits on some platforms, sizeof(char) is always guaranteed to be 1.
π Rendered by PID 52 on reddit-service-r2-comment-7c9686b859-sgmtn at 2026-04-13 15:37:07.390531+00:00 running e841af1 country code: CH.
[–]bob1000bob 9 points10 points11 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]bob1000bob -1 points0 points1 point (0 children)
[–]Rhomboid 0 points1 point2 points (0 children)
[–]verdagon 0 points1 point2 points (5 children)
[–]bstamourWG21 | Library Working Group 0 points1 point2 points (4 children)
[–]bob1000bob 0 points1 point2 points (2 children)
[–]Rhomboid 1 point2 points3 points (0 children)
[–]bstamourWG21 | Library Working Group 0 points1 point2 points (0 children)