24)
What is the output of C Program with functions.?
static void show();
int main()
{
printf("ROCKET ");
show();
return 0;
}
static void show()
printf("STATIC");
}
A) ROCKET
B) ROCKET STATIC
C) STATIC ROCKET
D) Compiler error
1
Answers
Explanation:
The basic input/output functions are getchar , putchar , puts , scanf and printf . The first two functions, getchar and putchar, are used to transfer single characters.
Concept:
A large program in C can be broken down into basic building blocks called functions. A function includes a collection of programming statements enclosed by { }.
Given:
#include <stdio.h>
static void show(); //function declaration
int main()
{
printf("ROCKET ");
show(); //function call
return 0;
}
static void show() //function definition
{printf("STATIC");
}
Find:
Find the output of the given statement.
Solution:
In C, a function has three aspects:
1. Function declaration - It tells about the function name, return type, and function parameters. A function should be declared globally.
Syntax: return_type function_name (argument list);
2. Function call - A declared function gets executed when it is called.
Syntax: functions_name(argument_list);
3. Function definition -
It includes the actual statements which are to be executed.
Syntax: return_type function_name (argument list) {function body;}
in the given code, there is one function named 'show'. It is called after the printf("ROCKET "); statement, therefore ROCKET will get printed first and then STATIC will be printed.
Output:
ROCKET STATIC