typedef in c++ a code example

Example 1: typedef in c

typedef struct
{
  	//add different parts of the struct here
 	string username;
  	string password;
}
user; // name of struct - you can name this whatever

user example; //variable of type user

example.username = "Comfortable Caterpillar"; // username part of example variable
example.password = "password" // password part of example variable
  
if (user.username == "Comfortable Caterpillar")
{
	printf("upvote this if it helped!");
}

Example 2: c++ typedef

// typedef [type] [alias]
// Example:
typedef unsigned long int ulong;

ulong someNumber = 158426;

Example 3: whats a typedef in c++

#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;
}

Tags:

C Example