For the sake of need, I have recently studied C + +. A simple familiarity with this language that I have forgotten for years. As a study, record here. The difference between C and C + + is also compared.
Code for C:
#include <stdio.h>
#include <stdlib.h>
/**
* 定义一个结构体
*/
struct Location {
int x; // 横坐标
int y; // 纵坐标
} location;
int main(void) {
printf("输入X坐标:\t\n");
int x;
scanf("%d", &x);
location.x = x;
printf("输入Y坐标:\t\n");
int y;
scanf("%d", &y);
location.y = y;
printf("X坐标是:\t%d\n", location.x);
printf("Y坐标是:\t%d\n", location.y);
// 做倒三角打印
int i;
for (i = 0; i < y; i++) {
printf("%d\t", i + 1);
int j;
for (j = i; j < x; j++) {
printf("* ");
}
printf("\n");
}
return EXIT_SUCCESS;
}
This uses the structure body location and generates an instance location. Enter numbers by scanf to X and Y. Assigns a value to the variable x of the struct location in location.x = x; Thus we can see that the structure is the object-oriented foundation, especially the predecessor of the data object.