Practice Question and Answer

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

DRAVID When a structure is assigned, passed, or returned, the copying is done monolithically. This means that the copies of any pointer fields will point to the same place as the original. In other words, anything pointed to is not copied. Hence, on changing the name through e2.n it automatically changed e1.n

Q: How would you check whether the contents of two structure variables are same or not? 1810 0

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

struct emp {      char n[20];       int age; }; main() {     struct emp e1 = {"Dravid", 23};    struct emp e2;    scanf ("%s %d",e2.n, & e2.age);    if( structcmp (e1,e2) ==0)         printf ("The structures are equal");    else          printf ("The structures are unequal"); } structcmp ( struct emp x, struct emp y) {      if (strcmp (x.n,y.n) ==0)            if (x.age == y.age)             return (0);             return (1); } In short, if you nee to compare two structures, you'll have to write your own function to do so which carries out the comparison field by field.

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

EOF has been defined as #define EOF -1 n the file "stdio.h" and an unsigned char ranges from 0 to 255 hence when EOF is read from the file it cannot be accommodated in ch. Solution is to declare ch as an int.

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

The last line from the file "trial" would be read twice. To avoid this, ues:        While ( fgets (str, 80, fp) ! = NULL)                puts (str);

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

C: \SAMPLE.EXE

Q: If the following program (myprog) is run from the command line as  myprog 1 2 3  what would be the output? main(int argc, char *argv[]) {     int i, j = 0;     for (i = 0; i < argc ; i++)            j = j + atoi ( argv[i]);     printf ("%d", j); } 1722 0

  • 1
    123
    Correct
    Wrong
  • 2
    6
    Correct
    Wrong
  • 3
    Error
    Correct
    Wrong
  • 4
    "123"
    Correct
    Wrong
  • Show AnswerHide Answer
  • Workspace

Answer : 2. "6"
Explanation :

Answer: B) 6 Explanation: When atoi() tries to convert argv[0] to a number it cannot do so (argv[0] being a file name) and hence returns a zero.

Q: What would be the output of the following program ? main()  {        unsigned  int a = oxffff;         ~a;         printf ("%x", a); } 1573 0

  • 1
    ffff
    Correct
    Wrong
  • 2
    0000
    Correct
    Wrong
  • 3
    00ff
    Correct
    Wrong
  • 4
    None of the above
    Correct
    Wrong
  • Show AnswerHide Answer
  • Workspace

Answer : 1. "ffff"
Explanation :

Answer: A) ffff Explanation:

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully