Chapter - 7, Pointer, HSSC-II (12th Class) Computer Science Key Point Notes

Chapter - 7, Pointer, HSSC-II (12th Class) Computer Science Key Point Notes

12th Class (HSSC-II) Computer SLO Based Key Point Notes

(National Book Foundation - As Federal Textbook Board, Islamabad 
Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards) 

{Contact WhatsApp 03339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}

************************************

👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************

Unit 7: Pointer

7.1.1 Pointer Variable:

  • A pointer is a type of variable that is used to store the address of a variable as a value.
  • It is used to refer to the memory location using its address.
  • It can access and manipulate the data in memory directly using the address.

Advantages of Pointer:

It can access the memory location directly.


7.1.2 Memory Address

  • Anything that is stored in memory (i.e. RAM) is assigned an address by the operating system.
  • The memory address is the physical address of a location in computer memory.
  • When a programmer declares a variable, the compiler reserves a memory location for the variable and assigns an address. The name of a variable is used to refer to the memory location occupied by a variable in the program.

7.1.3 Reference or Address Operator (&):

  • – In C++, the address or reference operator (&) is used to provide the address of the memory location of a variable.
  • – It is placed before the name of a variable. i.e. &x;

Example

#include <iostream.h>
#include <conio.h>
void main()
{
        clrscr();
        int x=10;
        cout<<“The address of x is “<<&x<<endl;
        cout<<“The value of x is “<<x<<endl;
        getch();
}


7.1.4 Dereference Operator (*)

The dereference operator (*) is used to access or use the value of a variable through a pointer.

Example:

#include <iostream.h>
#include <conio.h>
void main()
{
            clrscr();
            int a=10;
            int *ptr1 = &a;
            cout<<ptr1<<“ -------”<<*ptr1<<endl;
            *ptr1 = *ptr1 + 19;
            cout<<ptr1<<“-------”<<*ptr1<<endl;
            getch();
}


7.1.5 Declaration of a Pointer

  • A pointer can be declared by putting an asterisk (*) symbol before the name of a variable. i.e.
            Data_type *variable_name;

For Example: 
            int *ptr;
            float *abc;

  • A pointer can only point to a variable of the same data type as a pointer. i.e. a pointer of integer data type can only point to a variable of integer data type and cannot to some other types of variable.
  • A pointer of type void is a special type of pointer that can point to a variable of any data type.
  • The syntax of declaring a pointer of void type is as follows:
            void *pointer_name;

7.1.6 Initialization of Pointer

  • Assigning values to pointers at declaration time is called pointer initialization.
  • Values of pointers are the addresses of other variables. 
            Data_type *pointer_name = &variable_name;

For example: 
            int a=23;
            int *abc = &a;

Example

#include <iostream.h>
#include <conio.h>
void main()
{
            clrscr();
            int a=10;
            float y=20.55;
            int *ptr1 = &a;
            float *ptr2;
            void *ptr3;
            ptr2 = &y;
            ptr3 = &a;
            ptr3 = &y;
            getch();
}



************************************
👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************


************************************
Shortcut Links For:

1.  5th Class All Subjects Notes

2.  8th Class All Subjects Notes

3.  Easy English Grammar Notes



1. Website for School and College Level Physics   
2. Website for School and College Level Mathematics  
3. Website for Single National Curriculum Pakistan - All Subjects Notes 

© 2023 & onwards Academic Skills and Knowledge (ASK  

Note:  Write me in the comments box below for any query and also Share this information with your class-fellows and friends.

Post a Comment

0 Comments

cwebp -q 80 image.png -o image.webp