C + + Learning

Source: Internet
Author: User

Fan lie 0 starting point learning C + +

Chapter 3rd Declaration and definition of the 4th section function

1#include <iostream>2 using namespacestd;3 //The use of functions in the program, must be declared, and then defined, function declaration called function prototype, function definition called function implementation4 //The purpose of the declaration is to tell the compiler what the name of the function you are about to define, what type of return value, and what the parameter is .5 //The definition is to tell the compiler what the function is. If you do not declare a function, this function cannot be used by other function bars. 6 intAddintXinty);//declarations of functions, X and y can omit int add (int, int);7 intMain ()8 {9     return 0;Ten } One intAddintXintY//the implementation of the function, where x, Y is required, the return value is type int, the compiler will pre-set aside 4 bytes of space to the function, the argument is two int, also leave 8 bytes space A { -     returnX +y; -}

The 6th Chapter 4th section declares a class

1#include <iostream>2 using namespacestd;3 /*4 declares human This class, and does not allocate memory for it, just tells the compiler: What human is, what type of data it contains,what the function is. Also tell the compiler how large the class is, the size of the class is determined by the variables of that class, which has two member variables6 Height,weight. They are all int types, so the size of the class is 2*4=8 bytes. Methods of this class do not consume memory because we do notclaim types, and their return values are void.8 */9 classHuman//declaring the Human classTen { One      Public://indicates that all subsequent members are public, and public means that objects of that class can access these members directly A         voidgetheight (); -         voidgetweight (); -     Private://indicates that subsequent members are private, cannot be accessed directly by the object, and must be accessed through public member functions.  the         intheight; -         intweight; -      -};//this ends with a semicolon . + voidMain () - { +}

C + + Learning

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.