The episodes for C++ beginners

 The second the position for path_file_2.read() is related with loop number j. The correct answer should be like fowllowings:

A good way to replace memcpy() function:

#include <iostream>

int main()
{
    char *buffer = new char[10*sizeof(int)];
    for (int i = 0; i < 10; i++){
        *(int *)(buffer + i*sizeof(int)) = i;
    }
    // cout the third element in buffer
    std::cout << *(int *)(buffer + 2*sizeof(int)) << std::endl;
    return 0;
}

The corresponding results:
 

2

1. 如何使用cout在C++的代码里面:

outputs:

the codes: 

// c++ for beginner
/* what is C++ (general purpose, complied and case-sensitive)
    C++ understandable and easy to use, fast execution of demanding 
    tasks.  the source codes need to be complied into machine code 
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
    std::cout << "Hello, world!" << std::endl;
    std::cout << "my name is saldina.\n";
    std::cout << "today is tuesday." << std::endl;
    return 0;
}

what is the variable? what is the datatypes?

// c++ for beginner
/* what is variable? variable is just like a container 
and you could store some data types. 
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
    float annualSalary = 50000.99;
    float monthlySalary = annualSalary / 12;
    std::cout << "your monthly salary is " << monthlySalary << std::endl;
    return 0;
}

 what is the function of cin:

// c++ for beginner
/* what is variable? variable is just like a container 
and you could store some data types. 
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
    // float annualSalary = 50000.99;
    float annualSalary;
    std::cout << "please enter your annual salary" << std::endl;
    std:: cin >> annualSalary;
    float monthlySalary = annualSalary / 12;
    std::cout << "your monthly salary is " << monthlySalary << std::endl;
    std::cout << "in 10 years , you will earn:" << annualSalary*10 << std::endl;
    return 0;
}

The kinds of all variables :

the size of int is 4bytes
int min value is -2147483648
int max value is 2147483647

The corresponding codes:

// c++ for beginner
/* what is variable? variable is just like a container 
and you could store some data types. 
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
    int yearOfBirth = 1995;
    char gender = 'f';
    bool isOlderThan18 = true;
    float averageGrade = 4.5; 
    double balance = 45165453646;

    std::cout << "the size of int is " << sizeof(int) << "bytes" << std::endl;
    std::cout << "int min value is " << INT_MIN << std::endl;
    std::cout << "int max value is " << INT_MAX << std::endl;
    return 0;
}

the outputs:

The correspongding codes:

// c++ for beginner
/* what is variable? variable is just like a container 
and you could store some data types. 
*/
#include <stdio.h>
#include <iostream>
#include <iomanip>
int main()
{
    int yearOfBirth = 1995;
    char gender = 'f';
    bool isOlderThan18 = true;
    float averageGrade = 4.5; 
    double balance = 45165453646;

    std::cout << "the size of int is " << sizeof(int) << "bytes" << std::endl;
    std::cout << "int min value is " << INT_MIN << std::endl;
    std::cout << "int max value is " << INT_MAX << std::endl;
    std::cout << "UInt max value is " << UINT_MAX << std::endl;
    std::cout << "the size of unsigned int is " << sizeof(unsigned int) << "bytes" << std::endl;
    std::cout << "the size of char is " << sizeof(char) << "bytes\n";
    std::cout << "the size of float is " << sizeof(float) << "bytes" << std::endl;
    std::cout << "the size of double is " << sizeof(double) << "bytes" << std::endl;
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值