`
gcgmh
  • 浏览: 354320 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

C++ code segments

阅读更多
一.function alias invocation(引用)

#include <iostream>
using namespace std;
void aliasFun(int &, int &);
int main()
{
        int num = 10;
        cout << "Num = " << num << endl;
        int &i = num;
        i = 20;
        cout << "i = " << i << endl;
        cout << "Num = " << num << endl;
        int x = 200;
        int y = 300;
        aliasFun(x,y);
        cout << "x = " << x << ", " << "y = " << y << endl;
        return 0;
}
void aliasFun(int &a,int &b)
{
        a = 4;
        b = 10;
}

--------------------------------------------
二.type cast
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
        double d = 3.1415926;
        int i1 = static_cast<int>(d);
        int i2 = (int)d; // old method
        cout << "i1 = " << i1 << endl;
        cout << "i2 = " << i2 << endl;
        return 0;
}

-----------------------------------------

3.Array definition

int a[4]; // definition
int a[4] = {1,10,2,4} // defination and initialization

------------------------------------------

4.pointer
int a = 10;
int *p = &a;
int *p = new int; 
int *p = new int[10]; //dynamic allocate array
delete p;
delete [] p;

void swap(int *num1,int *num2)
{
    int temp = *num1;
    *num1 = *num2;
    *num2 = temp;
}

int main(){
    int x = 10;
    int y = 20;
    swap(&x,&y);
}

-------------------------------

5.character && string
        char *p = "hello very good";
        while(p != "\0")
        {
                cout << *p++;
        }

------------
        char str[10] = "hello!";
        char *p = str;
        for(int i=0;i<6;i++)
        {
                cout << *(p+i);
        }



分享到:
评论

相关推荐

    Realistic Ray Tracing.2nd.ed + Example Code

    Concentrating on the ... Most importantly, Realistic Ray Tracing adds many C++ code segments, and adds new details to provide the reader with a better intuitive understanding of ray tracing algorithms.

    Professional C++, 4th Edition

    Utilize real-world program segments in your own applications C++ is notoriously complex, and whether you use it for gaming or business, maximizing its functionality means keeping up to date with the ...

    c++Textbook

    A solid foundation in the basics of C++ programming will allow readers to create efficient, elegant code ready for any production environment Learning basic logic and fundamental programming ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to ...

    LeetCode最全代码

    201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/) | [C++](./C++/bitwise-and-of-numbers-range.cpp) [Python](./Python/bitwise-and-of-numbers-range.py) | _...

    用WIGGLER在IAR调试FLASH及RAM例程说明文档.pdf

    // Code segments - maybe placed anywhere in memory. // ------------- // // INTVEC -- Exception vector table. // SWITAB -- Software interrupt vector table. // ICODE -- Startup (cstartup) and exception ...

    OllyICE,od

    OllyDbg 可以扫描Object文件/库(包括 OMF 和 COFF 格式),解压代码段[code segments]并且对其位置进行定向。 Implib扫描。 由于一些DLL文件的输出函数使用的索引号,对于人来说,这些索引号没有实际含义。如果...

    Linkers and Loaders.pdf

    书中还介绍了两次通过链接(Two-pass linking),这通常用于处理对象代码库(Object code libraries)和重定位(Relocation)以及代码修改。 书中的第二章专注于系统架构相关问题,例如应用二进制接口(Application...

    linkers and loaders

    - **C++重复移除**:在C++编程中,为了避免多次定义相同的全局对象,编译器会在链接阶段自动去除重复的定义。 #### 结论 通过以上内容,我们可以看出链接器与加载器在计算机程序的构建和运行中扮演着极其重要的...

    Linker and Loaders.pdf

    - **特殊段(Common Blocks and Other Special Segments)**:例如C++的静态对象构造和析构函数,以及IBM 360架构中的RLD和END记录。 书中通过丰富的实例和深入的分析,阐述了链接和加载过程中的复杂性,并提供了...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX Add moving block for first and last connector's segments also for non-orthogonal connectors. - FIX Class TPenProp rewrote without TPen delphi object. - FIX In some cases TFlexCurve.Paint ...

    DB2的安装过程,V8.2

    确保系统已经安装了兼容的C++库。在Linux环境下,通常需要安装`compat-libstdc++`包。例如,在安装盘上找到`compat-libstdc++-7.3-2.96.118.i386.rpm`或`compat-libstdc++-33-3.2.3-47.3.x86_64.rpm`,然后使用以下...

    VB编程资源大全(英文源码 控件)

    docking.zip This ActiveX control and Demo will allow you to dock your toolbars/forms to a mdiform much in the way in which Visual C++ allows you to. &lt;END&gt;&lt;br&gt;17 , resizable7segment_source.zip An...

    USB Complete 3rdEdition

    Using Visual C++ .NET 284 Using Visual Basic .NET 286 Finding Your Device 291 Obtaining the Device Interface GUID 292 Requesting a Pointer to a Device Information Set 293 Identifying a Device ...

    Arduino七段计数器-项目开发

    首先,`code.ino`是Arduino项目的源代码文件,它包含了用C++编写的程序。在这个项目中,我们需要理解如何编写Arduino代码来控制七段显示器。代码通常会包括初始化引脚(pin setup),设置计数器变量,以及定义函数来...

Global site tag (gtag.js) - Google Analytics