alignof operator in C++ Last Updated : 08 Jun, 2018 Comments Improve Suggest changes Like Article Like Report In C++11 the alignof operator used to returns the alignment, in bytes of the specified type. Syntax: alignof(type) Syntax Explanation: alignof: operator returns the alignment in byte, required for instances of type, which type is either complete type, array type or a reference type. array type: alignment requirement of the element type is returned. reference type: the operator returns the alignment of referenced type. Return Value: The alignof operator typically used to returns a value of type std::size_t. Program: CPP // C++ program to demonstrate alignof operator #include <iostream> using namespace std; struct Geeks { int i; float f; char s; }; struct Empty { }; // driver code int main() { cout << "Alignment of char: " << alignof(char) << endl; cout << "Alignment of pointer: " << alignof(int*) << endl; cout << "Alignment of float: " << alignof(float) << endl; cout << "Alignment of class Geeks: " << alignof(Geeks) << endl; cout << "Alignment of Empty class: " << alignof(Empty) << endl; return 0; } Output: Alignment of char: 1 Alignment of pointer: 8 Alignment of float: 4 Alignment of class Geeks: 4 Alignment of Empty class: 1 alignof vs sizeof: The alignof value is the same as the value for sizeof for basic types. Consider, this example: typedef struct { int a; double b; } S; // alignof(S) == 8 Above case, the alignof value is the alignment requirement of the largest element in the structure. Example program to demonstrate the difference between alignof and sizeof: CPP // C++ program to demonstrate // alignof vs sizeof operator #include <iostream> using namespace std; struct Geeks { int i; float f; char s; }; int main() { cout << "alignment of Geeks : " << alignof(Geeks) << '\n'; cout << "sizeof of Geeks : " << sizeof(Geeks) << '\n'; cout << "alignment of int : " << alignof(int) << '\n'; cout << "sizeof of int : " << sizeof(int) << '\n'; } Output: alignment of Geeks : 4 sizeof of Geeks : 12 alignment of int : 4 sizeof of int : 4 Comment More infoAdvertise with us Next Article alignof operator in C++ R rajasethupathi Follow Improve Article Tags : Misc C++ cpp-structure Practice Tags : CPPMisc Similar Reads Assignment Operators in C++ In C++, the assignment operator forms the backbone of computational processes by performing a simple operation like assigning a value to a variable. It is denoted by equal sign ( = ) and provides one of the most basic operations in any programming language i.e. assign some value to the variables in 6 min read Operators in C++ C++ operators are the symbols that operate on values to perform specific mathematical or logical computations on given values. They are the foundation of any programming language.Example:C++#include <iostream> using namespace std; int main() { int a = 10 + 20; cout << a; return 0; }Outpu 9 min read Bitwise Operators in C++ In C+, Bitwise Operators are the operators that are used to perform bit-level operations on the integers. While performing these operations, integers are considered as sequences of binary digits. These operators are useful for low-level programming, system programming, and optimizing performance.C++ 6 min read array::operator[ ] in C++ STL Array classes are generally more efficient, light-weight, and reliable than C-style arrays. The introduction of array class from C++11 has offered a better alternative for C-style arrays. array::operator[] This operator is used to reference the element present at position given inside the operator. 2 min read bitset operator[] in C++ STL bitset::operator[] is a built-in function in C++ STL which is used to assign value to any index of a bitset. Syntax: bitset_operator[index] = value Parameter: The parameter index specifies the position at which the value is to be assigned. Return Value: The function returns the value to the bit at t 2 min read Like