It's a C++ question. It's a very basic question.

Asked 2 years ago, Updated 2 years ago, 48 views

There are two questions. It's hard because there's no additional explanation when I read and study on my own.

The first question is, I want to know the difference between " and ". When I use char type or substitute variable, I use '', but if I use '', there is an error. I want to know the difference.

The second question is structure.

The problem is to replace the members of one structure with another.

struct Student {
char bloodType;
int stdNumber;
float grade; }; int main() {
Student s1, s2;
s1.bloodType = 'O';
s1.stdNumber = 337;
s1.grade = 3.3f;

[ s2.bloodType = s1.bloodType; s2.stdNumber = s1.stdNumber;
s2.grade = s1.grade;
];

return 0; } }

The answer is like this, but I didn't do the part where I was substituting, but I ended up with s1=s2; and there was an error when the message window popped up. Definitely in the lead

int main() { struct Point { int x; int y; };

Point pt1={30,50}; Point pt2;

pt2=pt1;

I'd like to know why it doesn't apply to the question up there when I got the same value as the answer sheet. I'd really appreciate it if you could answer me.

c++

2022-09-22 18:35

1 Answers

#include <iostream>
using namespace std;

struct Student {
    char bloodType;
    int stdNumber;
    float grade;
};

int main() {
    Student s1, s2;
    s1.bloodType = 'O';
    s1.stdNumber = 337;
    s1.grade = 3.3f;

    cout <<"Information of s1" << endl;
    cout << s1.bloodType << endl;
    cout << s1.stdNumber << endl;
    cout << s1.grade << endl;

    s2 = s1;

    cout <<"Information of s2" << endl;
    cout << s2.bloodType << endl;
    cout << s2.stdNumber << endl;
    cout << s2.grade << endl;

    return 0;
}

The same structure can be used as a substitution operator.

'' is used to express characters. For example, the letter a, the letter '1', the letter '#'. Like this.

The " ", on the other hand, is used to represent a string. For example, the string "Hello", the string "World", and the string "a" exist.

So 'a' and 'a' are different things.

참Reference

Variable: http://itguru.tistory.com/7?category=194983

String: http://itguru.tistory.com/29?category=194983


2022-09-22 18:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.