
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 Articles
- Difference between strlen() and sizeof() for string in C
- Difference between strlen() and sizeof() for string in C Program
- What's the difference between window.location and document.location?
- What's the difference between Matplotlib.pyplot and Matplotlib.figure?
- What's the difference between "!!" and "?" in Kotlin?
- What's the Difference between Skills and Competencies?
- What's the difference between Tkinter's Tk and Toplevel classes?
- What's the difference between "STL" and "C++ Standard Library"?
- 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?
- What's the difference between "update" and "update_idletasks" in Tkinter?
- What's the difference between nohup and ampersand (&) on Linux?
- Difference Between PGP and S/MIME
- What is the difference between Eulicd's division lemma and algorithm?

Advertisements