C++中的cout<<…<<endl

#include "stdafx.h"

#include <iostream.h>

int main(int argc, char* argv[])
{
    int a=5;
    int *b=&a;
    *b=10;
    cout<<"a="<<a<<endl;  //shows a=10
    cout<<"b="<<b<<endl; //shows the address of variable a
    return 0;
}

指针b指向a的地址。

cout表示输出,先输出"a=",再输出a的值10。

若删除"a=",则只输出a的值10;若删除endl,则不换行。

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s