The sizeof keyword is a compile-time unary operator that determines the size of a variable or data type in bytes. sizeof() operator is used in different way according to the operand type, i.e,
Syntax:
sizeof(type)
OR
sizeof expression
#include <iostream>
using namespace std;
int main() {
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
return 0;
}
Size of char : 1
Size of int : 4
Size of short int : 2
Size of long int : 8
Size of float : 4
Size of double : 8
Size of wchar_t : 4
The typedef keyword allows programmers to create new names for types such as int or, more commonly in C++, templated types; it literally means “type definition.” Typedef can be used to improve the clarity of your code as well as to make changes to the underlying data types that you use easier.
Syntax:
typedef existing_name alias_name
#include <iostream>
int main(){
typedef unsigned int ui;
ui i = 5, j = 8;
std::cout << "i = " << i << std::endl;
std::cout << "j = " << j << std::endl;
return 0;
}
i = 5
j = 8
typedef and Pointers: Pointers can also be given an alias name using typedef.
For instance,
typedef int* Ptr ;
Ptr x, y, z;
Note: also read about the Operators in C++
If you like my post, please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…