Although there are no gifts, I hope you can take a look at these small questions about pointers.

Source: Internet
Author: User

It is still related to pointers and memory. Recently I read Mr Lin'sArticle, Write someCodeIf you are interested, let's take a look. What are the answers?

ProgramIt is compiled with vc6 + SP6, with compilation problems and runtime problems...

Q1-Q8, all output what content ???

(Temporarily put the homepage for a few days and withdraw it at that time)

# Include "string. H"

# Include "stdlib. H"

Char * getname (void ){

Char name [20] = "juqiang ";

Return name;

}

Int getsize (char Buf []) {

Return sizeof (BUF );

}

Int main (INT argc, char * argv [])

{

Char Buf [] = "hello ";

Printf ("size of BUF is: % d \ r \ n", sizeof (BUF); // Q1

Printf ("size of BUF calling is: % d \ r \ n", getsize (BUF); // Q2

Printf ("Hello % s \ r \ n", getname (); // Q3

 

Char * P = (char *) malloc (100 );

Int paddr = (INT) P;

Free (P );

Int paddr2 = (INT) P;

Printf ("paddr equals paddr2 is: % d \ r \ n", paddr = paddr2); // Q4

If (null! = P ){

Strcpy (P, "Hello! ");

}

Printf ("the contents of P is: % s", P); // Q5



Char name [] = "juqiang ";

Name [0] = 'J ';

Name [1] = 'U ';

Printf ("name is: % s \ r \ n", name); // Q6



Char bufname [] = "juqiang ";

Char * name2 = bufname;

* (Name2 + 0) = 'J ';

* (Name2 + 1) = 'U ';

Printf ("name is: % s, % s \ r \ n", bufname, name2); // Q7

 

Char * name3 = "juqiang ";

* (Name3 + 0) = 'J ';

* (Name3 + 1) = 'U ';

Printf ("name is: % s \ r \ n", name3); // Q8

 

Return 0;

}

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.