Codex (i) of C + + learning

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.