Sie sind auf Seite 1von 5

REPORT

PROGRAMMING AND COMPUTER


APPLICATION PRACTICES

“POINTER”

By:

Wildan Aghniya

17063048

ELECTRICAL EDUCATION

FACULTY OF ENGINEERING

PADANG STATE UNIVERSITY

2019
Purpose

1. Explain about concept variable pointer.


2. Explain about pointer array.
3. Explain about pointer string.
4. Explain about array pointer.
5. Explain about pointer in function.
6. Explain about pointer as parameters function.
7. Explain about pointer who pointed pointer.

Short theory

Basic Concept pointer

Pointer variables are often said to be variables that point to other objects. In reality, a
pointer variable contains the address of another object (i.e. an object that is said to be pointed
by a pointer).

Declaring Pointer Variables

with types can be any type that has been discussed in the previous chapters, as well as
the following chapters. The variable_name is the name of the pointer variable.

In C, you can create a special variable that stores the address (rather than the value).
This variable is called pointer variable or simply a pointer.

Above statement defines, p as pointer variable of type int.

Setting the Pointer to Point to Other Variables

In order for a pointer to point to another variable, the pointer must first be filled with
the address of the variable to be designated. To state the address of a variable, the operator &
(address operator, unary) can be used, by placing it in front of the variable name.

Accessing the Content of a Variable Through a Pointer

If a variable has been designated by a pointer, the variable pointed to by the pointer
can be accessed through the variable itself (direct access) or through a pointer (indirect
access). Indirect access is done by using an indirection operator (indirect) in the form of a
symbol * (unary).
Access and change the contents of a Pointer Variable

As in the basic concept, pointers can be used to access another variable through its
address, it can take, read / access and change the value of a variable. To be able to access the
value on a variable can use the * (star) before the variable name, so that it indicates that the
pointer variable will read the value of the designated address.

pointer to array

In most contexts, array names "decays" to pointers. In simple words, array names
are converted to pointers. That's the reason why you can use pointer with the same name as
array to manipulate elements of the array. However, you should remember that pointers and
arrays are not same.

pointer to string

The variable name of the string str holds the address of the first element of the array
i.e., it points at the starting memory address.

So, we can create a character pointer ptr and store the address of the string strvariable
in it. This way, ptr will point at the string str. In the following code we are assigning the
address of the string str to the pointer ptr.

Array of Pointer

An array can be used to store a number of pointers. The pointer array can be
initialized when declared.

Pointer to Pointer

A pointer to a pointer is a form of multiple indirection, or a chain of pointers.


Normally, apointer contains the address of a variable. When we define a pointer to a pointer,
the first pointercontains the address of the second pointer, which points to the location that
contains the actual value.

Pointer in function

Pointers and their relation to functions that will be discussed below include:
 Pointers as function parameters.
 Pointers as output functions.

Pointer as parameters function

The application of pointers as parameters is if desired so that the value of an


internal variable can be changed by the function called.

Pointer as output function

A function can be made so that the output is a pointer. For example, a function
produces an output in the form of a pointer that points to the month__name string,
Work Steps

1. turn on the computer.


2. Select Start at the bottom left corner of the monitor.
3. Select program.
4. Select program dev c++.
5. If the dev c ++ screen is out, Select File.
6. Select new to open a new program, or open to fine the program you have been made
before.
7. Typing the program like what in the data od the program.
8. After typing is done, select file, save as, and give the name the program like what you
want in the practicum.
9. Compile and run the program to see the truth of the typing.
10. See the results monitored and recorded, then analyze the results of the experiment.
11. Do the prcticum for the next file program with the same way.

Result

1.

Analysis
 The program above, the ouput show us value from Z is 50 and S is 30.
 In C language, #include can be used to impor functions that has been define from
header file.
 Printf() function used to display an output on the screen or monitor. The control string
like:
- %d to display integers.
- %f to display floating-point number.
- %c to display character.
- %s to to display string.
 \n is using to the new character will be in the new line from the program.
Conclusion
 The pointer variable type is a type of variable that contains the address of the actual
variable.
 The pointer variable type must be the same as the designated variable type.
 The relationship between pointers and arrays at C is very close, because actually
arrays will be translated internally in pointer form
 Pointer variables can be strings, arrays or other types of variables.
 A pointer can point to another pointer (pointer to pointer)
 Pointer variables can be used as parameters in a function, as can also be used as a
return value of a function.

References
 Jobsheet.
 https://www.programiz.com/c-programming/c-pointers-arrays.
 https://www.dyclassroom.com/c/c-pointers-and-strings.

Das könnte Ihnen auch gefallen