Struct un c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Struct un c++

Hi people, y habe a cuestión, how yo copy struct a in struct b ? Ej struct a={1,0,1} ; struct b {0,0,0} after copy ( b=a ) b {1,0,1}

2nd Nov 2019, 2:22 PM
Juan José Murcia
Juan José Murcia - avatar
3 Answers
0
#include <stdio.h> struct Number{ int x,y,z; }; int main() { struct Number n1 = {1,2,3}; struct Number n2 = n1; printf("%d\n",n1.y); printf("%d",n2.y); return 0; } Output is 2 for both cases.
2nd Nov 2019, 2:30 PM
Avinesh
Avinesh - avatar
0
That simple assignment used and when entering the function did not give me, just as capable somewhere can give me error, so I will try that code separately, but it was to know if it could. Thank you!
2nd Nov 2019, 2:36 PM
Juan José Murcia
Juan José Murcia - avatar
0
#include <iostream> using namespace std; int main() { int A; cout<<"Please Enter your choice : ";cin>>A; switch (A){ case 1:{ int r; int c; cout<<"please Enter number of rows : ";cin>>r; cout<<"Please Enter number of colums : ";cin>>c; for(int j = 0;j <= r-1;j++){ cout << "\n*"; for(int k = 0;k <= c-2;k++){ cout << " * ";} } break; } case 2:{ int r; cout << "Enter number of rows: "; cin >>r; for(int i = 1; i <= r; ++i) { for(int j = 1; j <= i; ++j) { cout << "* "; } cout << "\n"; } break; } case 3:{ int r; cout << "Enter number of rows: "; cin >> r; for(int i = r; i < 1; ++i) { for(int space = 0; space < r-i; ++space) cout << " "; for(int j = i; j <= 2*i-1; ++j) cout << "* "; for(int j = 0; j >= i-1; --j) cout << "* "; cout << endl; } break; } } return 0; }
28th Sep 2023, 5:15 PM
Nov Phany
Nov Phany - avatar