Tag: security

Questions Related to security

  1. scanf("%.8s", name);

  2. scanf("%8s", name);

  3. scanf("%8c", name);

  4. scanf("%s", name);


Correct Option: B
  1. Replace cin call in line 3 with gets() function.

  2. The length of input from cin cannot be limited. Use a larger array for fname.

  3. Use cin.width[20] before line 3.

  4. Use cin.size[19] before line 3.


Correct Option: C
  1. 4 - it is the size of the pointer

  2. 5 - it is the number of characters in the string that the pointer points to

  3. 4 - it is the size when 32000 is stored as integer

  4. 1 - it is the size of a character variable


Correct Option: A
int main(int argc,char* argv[]){
    int *ptr=new int;
    if(ptr==NULL)   exit(1);
    char *j;
    for(int i=1; i<=4;  i++) {
        j=argv[i];
        int k=atoi(j);
        if (k!=0){
            *ptr=k;
            delete ptr;
        }
    }
}

Will this program execute successfully ?

  1. program works when there is only 1 argument with program.

  2. program works when there are 3 arguments with program.

  3. program works when there are 4 arguments with program.

  4. program never executes successfully.


Correct Option: D
  1. A run-time error is encountered and the program aborts.

  2. unsigned int variables cannot store the sign (+ or -) of the number. The sign is discarded and only the number is stored in i.

  3. A large positive number will be stored in i.

  4. Unsigned int variables cannot store signed numbers. Hence in this program i will contain garbage values.


Correct Option: C
  1. 1289945278

  2. garbage. Integer j cannot hold such large values

  3. 9879879870

  4. Program is aborted.


Correct Option: A