c 语言 基本概念_C ++的基本概念

c 语言 基本概念

In this section we will cover the basics of C++, it will include the syntax, variable, operators, loop types, pointers, references and information about other requirements of a C++ program. You will come across lot of terms that you have already studied in C language.

在本节中,我们将介绍C ++的基础知识,包括语法,变量,运算符,循环类型,指针,引用以及有关C ++程序其他要求的信息。 您会遇到很多用C语言学习过的术语。

C ++程序的语法和结构 (Syntax and Structure of C++ program)

Here we will discuss one simple and basic C++ program to print "Hello this is C++" and its structure in parts with details and uses.

在这里,我们将讨论一个简单且基本的C ++程序,以打印“您好,这是C ++”及其部分结构,并附带详细信息和用法。

第一个C ++程序 (First C++ program)

#include <iostream.h>
using namespace std;
int main()
{
    cout << "Hello this is C++";
}

Header files are included at the beginning just like in C program. Here iostream is a header file which provides us with input & output streams. Header files contained predeclared function libraries, which can be used by users for their ease.

像C程序一样, 头文件也包含在开头。 iostream是一个头文件,可为我们提供输入和输出流。 头文件包含预定义的函数库,用户可以方便使用。

Using namespace std, tells the compiler to use standard namespace. Namespace collects identifiers used for class, object and variables. NameSpace can be used by two ways in a program, either by the use of using statement at the beginning, like we did in above mentioned program or by using name of namespace as prefix before the identifier with scope resolution (::) operator.

使用名称空间std ,告诉编译器使用标准名称空间。 命名空间收集用于类,对象和变量的标识符。 可以在程序中以两种方式使用NameSpace,或者像在上面提到的程序中那样在开头使用using语句,或者通过使用名称空间的名称作为具有作用域解析(::)运算符的标识符之前的前缀。

Example: std::cout << "A";

示例: std::cout << "A";

main(), is the function which holds the executing part of program its return type is int.

main()是保存程序执行部分的函数,其返回类型为int

cout <<, is used to print anything on screen, same as printf in C language. cin and cout are same as scanf and printf, only difference is that you do not need to mention format specifiers like, %d for int etc, in cout & cin.

cout << ,用于在屏幕上打印任何内容,与C语言中的printf相同。 cincoutscanfprintf相同,唯一的区别是您不需要在coutcin提及格式说明符,例如int等的%d

C ++程序中的注释 (Comments in C++ Program)

For single line comments, use // before mentioning comment, like

对于单行注释,请在提及注释之前使用// ,例如

cout<<"single line";   // This is single line comment
For multiple line comment, enclose the comment between /* and / **/ * /之间
/*this is 
  a multiple line 
  comment */

用C ++创建类 (Creating Classes in C++)

Classes name must start with capital letter, and they contain data variables and member functions. This is a mere introduction to classes, we will discuss classes in detail throughout the C++ tutorial.

类名称必须以大写字母开头,并且它们包含数据变量和成员函数。 这仅仅是对类的介绍,我们将在整个C ++教程中详细讨论类。

class Abc
{
    int i;           //data variable
    void display()         //Member Function
    { 
        cout << "Inside Member Function";
    }
}; // Class ends here

int main()
{
    Abc obj;  // Creatig Abc class's object
    obj.display();  //Calling member function using class object
}

This is how a class is defined, once a class is defined, then its object is created and the member functions are used.

这是定义类的方式,一旦定义了类,便创建其对象并使用成员函数。

Variables can be declared anywhere in the entire program, but must be declared, before they are used. Hence, we don't need to declare variable at the start of the program.

变量可以在整个程序中的任何位置声明,但必须在使用它们之前声明。 因此,我们不需要在程序开始时声明变量。

Don't worry this is just to give you a basic idea about C++ language, we will cover everything in details in next tutorials.

不用担心,这只是给您有关C ++语言的基本概念,我们将在下一个教程中详细介绍所有内容。

翻译自: https://www.studytonight.com/cpp/basics-of-cpp.php

c 语言 基本概念

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值