» » Reason for Data Insecurity

Reason for Data Insecurity

  • It is the  GLOBAL VARIABLES which leads to the data insecurity in c- programs 
  • GLOBAL VARIABLES would be available for both related and unrelated functions also.
  • Whenever an unrelated function accesses the data in a wrong way data corruption arises
Sample c -program  

#include <stdio.h>
 
/* global variable declaration */
int a = 20;
 
int main ()
{
  /* local variable declaration in main function */
  int a = 10;
  int b = 20;
  int c = 0; 
int mul=0;

  c = sum( a, b);
  printf ("a+b = %d\n",  c); 
 mul= sum( a, b);
  printf ("a*b= %d\n",  mul);  
 return 0;
}

/* function to add two integers */
int sum(int a, int b)
{
    

    return a + b;
}
/* function to multiply two integers */
int mul(int a, int b)
{


    return a * b;
} 

Java program:

 package com.instanceofjavaforus;

public class Student {
  
// variables
    int rno;
    String name;
    String clas;
  
//setter and getter methods of variables  
    public int getRno() {
        return rno;
    }

    public void setRno(int rno) {
        this.rno = rno;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getClas() {
        return clas;
    }

    public void setClas(String clas) {
        this.clas = clas;
    }

  
    //constructor
    Student(int rno,String name,String clas){
        this.rno=rno;
        this.name=name;
        this.clas=clas;
          }
  
    public static void main(String args[]){
      
        Student student= new Student(1, "sai", "class IV", "hyderabad", 1);
      
        System.out.println("Name: "+student.getName());
        System.out.println("Class: "+student.getClas());
        System.out.println("Rno: "+student.getRno());
       }
}

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu