int main() { int i, fss; char ch, source["> int main() { int i, fss; char ch, source[">
logo

CuriousTab

CuriousTab

Discussion


Home C Programming Input / Output See What Others Are Saying!
  • Question
  • On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?
    #include<stdio.h>
    
    int main()
    {
        int i, fss;
        char ch, source[20] = "source.txt", target[20]="target.txt", t;
        FILE *fs, *ft;
        fs = fopen(source, "r");
        ft = fopen(target, "w");
        while(1)
        {
            ch=getc(fs);
            if(ch==EOF)
                break;
            else
            {
                fseek(fs, 4L, SEEK_CUR);
                fputc(ch, ft);
            }
        }
        return 0;
    }
    


  • Options
  • A. r n
  • B. Trh
  • C. err
  • D. None of above

  • Correct Answer
  • Trh 

    Explanation
    The file source.txt is opened in read mode and target.txt is opened in write mode. The file source.txt contains "To err is human".

    Inside the while loop,

    ch=getc(fs); The first character('T') of the source.txt is stored in variable ch and it's checked for EOF.

    if(ch==EOF) If EOF(End of file) is true, the loop breaks and program execution stops.

    If not EOF encountered, fseek(fs, 4L, SEEK_CUR); the file pointer advances 4 character from the current position. Hence the file pointer is in 5th character of file source.txt.

    fputc(ch, ft); It writes the character 'T' stored in variable ch to target.txt.

    The while loop runs three times and it write the character 1st and 5th and 11th characters ("Trh") in the target.txt file.


    More questions

    • 1. What will be the output of the program if value 25 given to scanf()?
      #include<stdio.h>
      
      int main()
      {
          int i;
          printf("%d\n", scanf("%d", &i));
          return 0;
      }
      

    • Options
    • A. 25
    • B. 2
    • C. 1
    • D. 5
    • Discuss
    • 2. In the statement expression1 >> expression2. if expression1 is a signed integer with its leftmost bit set to 1 then on right shifting it the result of the statement will vary from computer to computer

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. What do the following declaration signify?
      int *ptr[30];

    • Options
    • A. ptr is a pointer to an array of 30 integer pointers.
    • B. ptr is a array of 30 pointers to integers.
    • C. ptr is a array of 30 integer pointers.
    • D. ptr is a array 30 pointers.
    • Discuss
    • 4. Range of float id -2.25e+308 to 2.25e+308

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. What will be the output of the program (in Turbo C under DOS)?
      #include<stdio.h>
      
      int main()
      {
          char huge *near *far *ptr1;
          char near *far *huge *ptr2;
          char far *huge *near *ptr3;
          printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
          return 0;
      }
      

    • Options
    • A. 4, 4, 8
    • B. 2, 4, 4
    • C. 4, 4, 2
    • D. 2, 4, 8
    • Discuss
    • 6. What will be the output of the program in 16-bit platform (under DOS)?
      #include<stdio.h>
      
      int main()
      {
          struct node
          {
              int data;
              struct node *link;
          };
          struct node *p, *q;
          p = (struct node *) malloc(sizeof(struct node));
          q = (struct node *) malloc(sizeof(struct node));
          printf("%d, %d\n", sizeof(p), sizeof(q));
          return 0;
      }
      

    • Options
    • A. 2, 2
    • B. 8, 8
    • C. 5, 5
    • D. 4, 4
    • Discuss
    • 7. Is it true that too many recursive calls may result into stack overflow?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 8. The operator used to get value at address stored in a pointer variable is

    • Options
    • A. *
    • B. &
    • C. &&
    • D. ||
    • Discuss
    • 9. If the size of integer is 4bytes, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int arr[] = {12, 13, 14, 15, 16};
          printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
          return 0;
      }
      

    • Options
    • A. 10, 2, 4
    • B. 20, 4, 4
    • C. 16, 2, 2
    • D. 20, 2, 2
    • Discuss
    • 10. What do the following declaration signify?
      void *cmp();

    • Options
    • A. cmp is a pointer to an void type.
    • B. cmp is a void type pointer variable.
    • C. cmp is a function that return a void pointer.
    • D. cmp function returns nothing.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment