Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ structure (Struct)

#include <iostream>

using namespace std;

struct book{
  string name;
  string author;
  int pages;
  float price;
};

int main(){
    book b1 = {"A tale of two cities", "William Shakespeare", 350, 99.9};
    cout << b1.name << endl;
}
Comment

structs in c++


#include <bits/stdc++.h>
#include <iostream>

#define ll long long

using namespace std;

struct student{
	int roll;
	string name;
	int age;
	
	void studentDetails(){
		cout<<"Name is "<<name<<" Age is "<<age<<" roll no is "<<roll<<endl;
	}
};


int main(){
	
	student sumant;
	sumant.roll = 30;
	sumant.name = "Sumant Tirkey";
	sumant.age = 18;
	
	sumant.studentDetails();
	cout<<endl;

    return 0;
}
Comment

c++ structure

// Can be outside or inside the main function
struct {
  string name;
  int age;
} user_data;

// The part you use the struct
cout << "What is your name? ";
cin >> user_data.name;

cout << "How old are you? ";
cin >> user_data.age;;

cout << endl << "Hello " << user_data.name << ", You are " << user_data.age << " years old!";
Comment

C++ Structures (struct)

struct {             // Structure declaration
  int myNum;         // Member (int variable)
  string myString;   // Member (string variable)
} myStructure;       // Structure variable
Comment

c++ struct

//function having struct as a parameter
#include <iostream>
#include <string>

using namespace std;

struct car{
    string name;
    string color;
    int maxSpeed;
    int model;
};

void fun (car x){
    cout << "Name: " << x.name << endl;
    cout << "Model: " << x.model << endl;
    cout << "Color: " << x.color << endl;
    cout << "Maximum speed: " << x.maxSpeed << endl;
}

int main(){
    car c1 = {"BMW", "Red", 250, 2022};
    car c2 = {"Mercedes", "Black", 220, 2019};
    fun (c1);
    fun (c2);
}
Comment

c++ structure

struct Point {
    int x;
    int y;
}
Comment

struct c++

//Struct is a compound data type that contains different variables of different types.
struct Student
{
    char stuName[30];
    int stuRollNo;
    int stuAge;
};
Comment

struct c++

struct Student
{
    string Nom;
    int Surn;
    int Age;
};
Comment

c++ structs

//
//  main.cpp
//  Structures
//

#include <iostream>
#include <string>
using namespace std;

struct variables {
    
    string greeting = "Hello, ";
    string name;
    
    string question = "How old are you? 
";
    int age;
    
};

int main() {
    struct variables introduction;
    
    cout << "What is your name?" << endl;
    cin >> introduction.name;
    cout << introduction.greeting << introduction.name << "!" << endl;
    cout << introduction.question;
    cin >> introduction.age;
    cout << "You are " << introduction.age << " years old." << endl;
    
    return 0;
}

/*
 * example run:
 * What is your name?
 * Alex
 * Hello, Alex!
 * How old are you?
 * 30
 * You are 30 years old.
 */
Comment

c++ struct

struct Block {
    vk::DeviceMemory memory;
    vk::DeviceSize offset;
    vk::DeviceSize size;
    bool free;
    void *ptr = nullptr; // Useless if it is a GPU allocation
 
    bool operator==(Block const &block);
};
bool Block::operator==(Block const &block) {
    if(memory == block.memory &&
       offset == block.offset &&
       size == block.size &&
       free == block.free &&
       ptr == block.ptr)
        return true;
    return false;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: 2-Dimensional array in c++ 
Cpp :: c++ friend class 
Cpp :: convert decimal to binary in c++ 
Cpp :: joins in mysql use sequelize 
Cpp :: C++ String Length Example 
Cpp :: c++ loop vector 
Cpp :: string to uint64_t c++ 
Cpp :: c++ pause linux 
Cpp :: cpp loop through object 
Cpp :: std::iomanip c++ 
Cpp :: rotate array cpp 
Cpp :: cpp string slice 
Cpp :: int to float c++ 
Cpp :: How to create files in C++ 
Cpp :: C++ Vector Operation Add Element 
Cpp :: how to set a variable to infinity in c++ 
Cpp :: c++ get maximum value unsigned int 
Cpp :: how to play sounds in c++ 
Cpp :: string length in c++ 
Cpp :: factorial calculator c++ 
Cpp :: pure virtual function in c++ 
Cpp :: c++ compile to exe command line 
Cpp :: gcc suppress warning inline 
Cpp :: c++ preprocessor operations 
Cpp :: how to create 2d array using vector in c++ 
Cpp :: system("pause") note working c++ 
Cpp :: is anagram c++ 
Cpp :: preorder 
Cpp :: c++ uint8_t header 
Cpp :: c++ string_t to string 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =