Bird
0
0

What will be the output of this C program?

medium📝 Predict Output Q4 of 15
C - Basics and Execution Environment
What will be the output of this C program?
#include <stdio.h>
#include "greet.h"

int main() {
    greet();
    return 0;
}

Assuming greet.h contains:
void greet() { printf("Hello!\n"); }
ACompilation error due to function definition in header
BHello!
CNo output
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand header content and usage

    The header greet.h defines a function greet() that prints "Hello!".
  2. Step 2: Analyze program behavior

    The program includes the header and calls greet() in main(), so it prints "Hello!".
  3. Final Answer:

    Hello! -> Option B
  4. Quick Check:

    Function in header runs = prints Hello! [OK]
Quick Trick: Functions can be defined in headers but beware of multiple includes [OK]
Common Mistakes:
  • Assuming function definitions in headers cause errors always
  • Expecting no output without checking function call
  • Confusing compile and runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes