Question B: basic operation of pointers (2)

Source: Internet
Author: User

 Question B: The basic operation of the pointer (2) The following program, input 10 100 and 100 10, can output max=100 min=10, please add the complete program
#include <iostream>
using namespace Std;
int main ()
{
int *p1,*p2,t;
This program is not allowed to add new variables, the following use the new operator to allocate space, and P1, p2 respectively save their address

Enter two integers below. If there is no space allocated above, this operation refers to bribery space, which is extremely dangerous.
cin>>*p1>>*p2;
The code added below, only appears p1,p2 and T, do not appear a and b

cout<< "max=" <<*p1<< "min=" <<*p2<<endl; P1 and P2 point to large and small values, regardless of the input size
Write down the statements that release P1 and P2 to the space

return 0;
} input

Two integers

Output

Output large and small values in the specified format

Sample input
10 100
Sample output
max=100 min=10
/* *copyright (c) 2014, Yantai University School of computer *all rights reserved. * File name: Test.cpp * Yang Hanning * Completion Date: December 4, 2014 * Version number: v1.0 * * Problem Description: Compare two number of sizes with pointers * Program input: * Program output: */#include <iostream>using Namespac e std;int Main () {    int *p1,*p2,a,b,t;    cin>>a>>b;    p1=&a;    p2=&b;    if (*P1<*P2)    {        t=*p1;        *P1=*P2;        *p2=t;    }    cout<< "max=" <<a<< "min=" <<b<<endl;    return 0;}


Question B: basic operation of pointers (2)

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.