Thread: quick question

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    51

    quick question

    Hey my book has an excercise that states the following:

    Examine the following program carefully. What is printed?

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	printf("Hello!\n");
    	fclose(stdout);
    	printf("Goodbye!\n";
    	return 0;
    }
    I ran it and it prints Hello? this seems to be to easy. Am I missing something?

  2. #2
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Yes. The closing parentheses on the second printf.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > printf("Hello!\n");
    Also known as
    fprintf(stdout,"Hello!\n");

    Can you now figure out what the consequence of closing stdout is?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Location
    Great India
    Posts
    24
    The stdout stands for STANDARD OUTPUT and when we close stdout the GOODBYE is not shown on the screen.

    That's all hidden logic is there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM