Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

cryptography foundations, Essays (university) of Cryptography and System Security

Cryptography is concerned with the construction of schemes that should maintain a desired functionality, even under malicious attempts aimed at making them deviate from it. The design of cryptographic systems has to be based on firm foundations; whereas ad-hoc approaches and heuristics are a very dangerous way to go. This work is aimed at presenting firm foundations for cryptography. The foundations of cryptography are the paradigms, approaches and techniques used to conceptualize, define and pr

Typology: Essays (university)

2020/2021

Uploaded on 07/14/2021

rokesh-kumar
rokesh-kumar 🇮🇳

2 documents

1 / 62

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
POINTERS
Sk.RaziyaSultana
Ass.Professor
CSE
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e

Partial preview of the text

Download cryptography foundations and more Essays (university) Cryptography and System Security in PDF only on Docsity!

POINTERS

Sk.RaziyaSultana Ass.Professor CSE

OBJECTIVES:

 (^) What is Pointer?  (^) what does "Address of a memory location" means?  (^) Declaring, Initializing and using a pointer variable  (^) Pointer address operators  (^) Pointer Expressions  (^) Pointer Arithmetic  (^) Pointer to a Pointer  (^) Pointers as Function Argument  (^) Pointer to Array  (^) Pointer to Strings  (^) Types Of Pointers  (^) Advantage of pointer  (^) Disadvantage of pointer

ADDRESS IN C  Whenever a variable is defined in C language, a memory location is assigned for it, in which it's value will be stored. We can easily check this memory address, using the & symbol.  If var is the name of the variable, then &var will give it's address.  (^) Let's write a small program to see memory address of any variable that we define in our program.

CONTINUE

#include<stdio.h> void main() { int var = 7; printf("Value of the variable var is: %d\n", var); printf("Memory address of the variable var is: %x\n", &var); }  (^) You must have also seen in the function scanf(), we mention &var to take user input for any variable var.  (^) scanf("%d", &var);  (^) This is used to store the user inputted value to the address of the variable var.

CONTINUE….

 Whenever a variable is declared in a program, system allocates a location i.e an address to that variable in the memory, to hold the assigned value.  The question is how we can access a variable using it's address? Since the memory addresses are also just numbers, they can also be assigned to some other variable. The variables which are used to hold memory addresses are called Pointer variables.  A pointer variable is therefore nothing but a variable which holds an address of some other variable. And the value of a pointer variable gets stored in another memory location.

CONTINUE
INITIALIZATION OF POINTER VARIABLE

Pointer Initialization is the process of assigning address of variable to a pointer variable. It contains the address of a variable of the same data type. In C language address operator & is used to determine the address of a variable. The & (immediately preceding a variable name) returns the address of the variable associated with it. Syntax: data-type *pointer-variable= &another-variable; or data-type *pointer-variable; pointer-variable= &another-variable eg: int a = 10; int *ptr; //pointer declaration ptr = &a; //pointer initialization  (^) Pointer variable always points to variables of the same datatype.

CONTINUE..

EXAMPLE:

#include <stdio.h> int main () { int var = 100 ; int * ptr; /pointer declaration/ ptr = &var; /pointer initialization/ printf(" \n Value of var= %d", *ptr); printf(" \n Address of var= %X", ptr); return 0 ; }

POINTER ADDRESS OPERATORS:

pointer Address operators: The & Operator (Address Of Operator) The "Address Of" Operator denoted by the ampersand character (&), & is a unary operator, which returns the address of a variable. After declaration of a pointer variable, we need to initialize the pointer with the valid memory address; to get the memory address of a variable Address Of" (&) Operator is used. Consider the program #include <stdio.h> int main() { int x=10; //integer variable int ptrX; //integer pointer declaration ptrX=&x; //pointer initialization with the address of x printf("Value of x: %d\n",ptrX); return 0; }

POINTER EXPRESSIONS

C supports a rich set of built-in operations like arithmetic, relational, assignment, conditional, etc. which can be performed on identifiers. Just like any other variable, these operations can be also performed on pointer variables.

ARITHMETIC OPERATORS

We can perform arithmetic operations to pointer variables using arithmetic operators. We can add an integer or subtract an integer using a pointer pointing to that integer variable. The given table shows the arithmetic operators that can be performed on pointer variables: Examples: *ptr1 + *ptr *ptr1 * *ptr *ptr1 + *ptr2 - *ptr We can also directly perform arithmetic expression using integers. Lets look at the example given below where p1 and p2 are pointers. p1+10, p2-5, p1-p2+10, p1/

EXAMPLE:

// Program showing pointer expressions // during Arithmetic Operations #include <stdio.h> int main() { // Integer variables int a = 20, b = 10; // Variables for storing arithmetic // operations solution int add, sub, div, mul, mod; // Pointer variables for variables // a and b int *ptr_a, *ptr_b; // Initialization of pointers ptr_a = &a; ptr_b = &b;

CONTINUE…

// Performing arithmetic Operations // on pointers add = *ptr_a + *ptr_b; sub = *ptr_a - *ptr_b; mul = *ptr_a * *ptr_b; div = *ptr_a / *ptr_b; mod = *ptr_a % *ptr_b; // Printing values printf("Addition = %d\n", add); printf("Subtraction = %d\n", sub); printf("Multiplication = %d\n", mul); printf("Division = %d\n", div); printf("Modulo = %d\n", mod); return 0; }  (^) Example: Incorrect: ptr_a/ptr_b; Correct: ptr_a / ptr_b; Correct: (ptr_a)/(ptr_b);