C Language Pointers

Source: Internet
Author: User

Lesson three Homework

A pointer is a variable that stores the memory address of a computer. Reading data from the memory pointed to by the pointer is called the value of the pointer. Pointers can point to variable addresses of specific types, such as int,long , and double. The pointer can also be a void type,aNULL Pointer, and an uninitialized pointer.

1)

#include <stdio.h>

int main ()

{

int *ptr; declares an int pointer

int val = 1; declares an int value

PTR = &val; Assigning a reference to an int value for a pointer

int deref = *ptr; value the pointer to print the contents stored in the pointer address

printf ("Deref address =%ld, value =%d\n", PTR, deref);

}

2. Pointers and Arrays

#include <stdio.h>

int main ()

{

int myarray[4] = {1,2,3,0};

int *ptr = myarray;

printf ("PTR address =%ld, value *ptr=%d\n", ptr,*ptr);

ptr++;

printf ("PTR address =%ld, value *ptr=%d\n", ptr,*ptr);

ptr++;

printf ("PTR address =%ld, value *ptr=%d\n", ptr,*ptr);

ptr++;

printf ("PTR address =%ld, value *ptr=%d\n", ptr,*ptr);

}

3)

#include <stdio.h>

struct Person {

int age;

Char *name;

};

int main ()

{

struct person first;

struct person *ptr;

First.age = 21;

Char *fullname = "full name";

First.name = fullname;

PTR = &first;

printf ("age=%d, name=%s\n", First.age, Ptr->name);

}


C Language Pointers

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.