0% found this document useful (0 votes)
592 views4 pages

Exercise 5

This document contains an exercise with multiple choice and written response questions about basic C programming concepts like header files, input/output functions, format specifiers, and the general structure of a C program. It tests understanding of printf(), scanf(), gets(), puts(), and other functions. Sample code is provided to demonstrate correct usage of various functions to display text, read input, and output values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
592 views4 pages

Exercise 5

This document contains an exercise with multiple choice and written response questions about basic C programming concepts like header files, input/output functions, format specifiers, and the general structure of a C program. It tests understanding of printf(), scanf(), gets(), puts(), and other functions. Sample code is provided to demonstrate correct usage of various functions to display text, read input, and output values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Exercise 5

Name: Mark Anthony R. Raymundo


Date: July 22, 2016
Year & Section: OU- PBDIT
Score:__________
A.
1. What are header files (#include)? What is the use of stdio.h and conio.h?
A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several source
files. There are two types of header files: the files that the programmer
writes and the files that come with your compiler. The use of #include tells
the preprocessor to treat the contents of a specified file as if they appear
in the source program at the point where the directive appears.
The stdio.h header defines three variable types, several macros, and
various functions for performing input and output.
The conio.h header used in c programming contains functions for
console input/output.
2. What is the use of the standard output printf()? Standard input scanf()?
Printf() is for writing output. Scanf() is for reading input.
There are subtle differences that are driven by that basic one--for
example, a single space in a printf() format string writes a single space of
output, but a single space in a scanf() format string skips across an
arbitrary amount of whitespace in the input.
Likewise, since scanf() needs to modify variables, nearly all the
parameters it receives (other than the format string) are pointers instead
of values (though printf expects pointers in a few cases as well, such as %s
and %n).
But in the end, the big difference is what they do: printf() writes
output, scanf() reads input.
3. Give the use of the following format specifiers:
%d
used to declare for decimal integers
%c
used to declare characters
%f
used to declare for floating point
%lf
used to declare doubles
4. Give the use of the following backslash character constants:
\n
New line
\ (double
Insert a double quote
quotes)
\ (single
Insert a single quote
quotes)
\\(backslash)
Insert a back slash character
5. Write the corresponding C statement to achieve the following output:
a. the sentence My User Friendly Guide to the C Programming displayed in
the screen
main()

{
printf(My User friendly Guide to the C Programming\n);
}
b. read the value of the integer variable first_int from the users input.
main()
{
int first_int;
scanf( %d, &first_int);
}
c. read the value of a float variable first_float from the users input.
main()
{
float first_float;
scanf( %f, &first_float);
}
d. display the value of the float variable first_float.
main()
{
int first_float;
scanf( %f, &first_float);
printf( %f\n, first_float);
}
e. display the value of the integer variable first_int.
main()
{
int first_int;
scanf(%d,&first_int);
printf(%d\n,first_int);
}
6. Describe the following console input/output functions (conio.h):
gets()This function takes the name of the string as an argument and
reads characters from the keyboard until ENTER key is pressed.
ENTER key is not stored as byte instead it is replaces by the null
terminator.
getch()reads a character with echo. Does not wait for carriage return or
ENTER key.
getche()- reads a character without echo. Does not wait for carriage return
or ENTER key.
puts()writes a string to the screen, followed by a newline. It can only
output a string of characters. It cannot output numbers or do
format conversion. It takes up less space and run faster.
putschar( writes a string (character) to the screen.
)clrscr()used to clear the output screen.

7. How do we begin and end segment in C?


In order to begin a statement using C language, you have to put {
sign on the start of your function and end this function with } sign.
8. Describe the General C Language Structure:
To write a C program, we first create functions and then put them
together. A C program may contain one or more sections as illustrated
below:
Documentation Section
Link Section
Definition Section
Global Declaration Section
Main() Function Section
{
Declaration Part
Executable Part
}
Subprogram Section
Function 1
Function 2
.
.
Function N
Documentation section: The documentation section consists of a set of
comment lines giving the name of the program, the author and other
details, which the programmer would like to use later.
Link section: The link section provides instructions to the compiler to
link functions from the system library.
Definition section: The definition section defines all symbolic constants.
Global declaration section: There are some variables that are used in
more than one function. Such variables are called global variables and
are declared in the global declaration section that is outside of all the
functions. This section also declares all the user-defined functions.
main () function section: Every C program must have one main
function section. This section contains two parts; declaration part and
executable part
o Declaration part: The declaration part declares all the variables
used in the executable part.
o Executable part: There is at least one statement in the
executable part. These two parts must appear between the
opening and closing braces. The program execution begins at the
opening brace and ends at the closing brace. The closing brace
of the main function is the logical end of the program. All
statements in the declaration and executable part end with a
semicolon.

Subprogram section: The subprogram section contains all the userdefined functions that are called in the main () function. User-defined
functions are generally placed immediately after the main () function,
although they may appear in any order.
Note: All section, except the main () function section may be absent when
they are not required.
B.
I
What will be the output of the following statements:
printf(Hello!\n);
Hello!
printf(The value of %5d is
The value of 5.00000 is five.
five.,5);
printf(\n\n Do you know the
next number? \n);
printf(\n %5d %6.2f, 6 ,6.5);
printf( Then followed by %d.,
7);
II.

Do you know the next number?


6

6.5

Then followed by 7.

Consider the following declaration:


int x,z;
char y;
float t;
double u;
Tell whether the following scanf( ) statements is valid or invalid.
Scanf(%d,&x);
invalid
scanf(%f%5d,&t,&z);
valid
scanf(%c,%c,%y,%y);
invalid
scanf (%lf,u);
invalid
y=getch();
valid
x=getch();
invalid

You might also like