

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What's the difference between sizeof and alignof?
Here we will see what are the differences of sizeof and the alignof operator in C++. The alognof() operator is introduced in C++11.
The alignof() operator is used to get the alignment in bytes. It requires instances of type. the type is either complete type or a reference type. There is another operator called the sizeof() operator, that returns the size of one type. For normal datatypes the sizeof and the alignof returns the same value. For some user defined datatype, the alignof returns some different value. Let us see the example to get the idea.
Example
#include<iostream> using namespace std; struct MyStruct{ int x; double y; char z; }; main() { cout << "The sizeof(MyStruct): " << sizeof(MyStruct) << endl; cout << "The alignof(MyStruct): " << alignof(MyStruct) << endl; }
Output
The sizeof(MyStruct): 24 The alignof(MyStruct): 8
- Related Questions & Answers
- Difference between strlen() and sizeof() for string in C
- What's the difference between window.location and document.location?
- What's the difference between Matplotlib.pyplot and Matplotlib.figure?
- Difference between strlen() and sizeof() for string in C Program
- What's the difference between Tkinter's Tk and Toplevel classes?
- What is the difference between Python's re.search and re.match?
- What's the difference between lists and tuples in Python?
- What's the difference between RSpec and Cucumber in Selenium?
- Difference Between PGP and S/MIME
- Difference between char s[] and char *s in C
- What's the difference between nohup and ampersand (&) on Linux?
- Difference Between Prim’s and Kruskal’s Algorithm
- What's the difference between assignment operator and copy constructor in C++?
- What's the difference between "!!" and "?" in Kotlin?
- Alignof operator in C++
Advertisements