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 are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu