1. Explain following unformatted I/O functions 1. gets() 2.
puts()
gets():
gets() function reads a group of characters or strings from the keyboard by the user and these
characters get stored in a character array. This function allows us to write space-separated
texts or strings. This function is declared in stdio.h(header file).
syntax:
gets(str); // where str is a character string variable.
1. puts():
In C programming puts() function is used to display a group of characters or strings which is
already stored in a character array. This function is declared in stdio.h(header file).
puts() function is used to display a character string on the monitor screen. It has the
following syntax:
puts(str); // where str is a string (array of characters)
Q Write a for loop to print from 1 to 10
#include <stdio.h>
int main() {
for(int i = 1; i <= 10; i++) {
printf("%d\n", i);
return 0;
}
The loop starts with i = 1.
It runs until i <= 10.
i increases by 1 in each iteration (i++).
printf("%d\n", i); prints the current value of i
Q Trace the following output
1. #include <stdio.h>
main()
int i;
for (i = 0; i< 10; i++)
{
if (i == 3)
break;
printf("%d\n", i);
}
Ans Given C Program:
#include <stdio.h>
int main() {
int i;
for (i = 0; i < 10; i++) {
if (i == 3) {
break;
printf("%d\n", i);
return 0;
Tracing the Output:
i = 0 → Condition 0 < 10 → i != 3 → Print 0
i = 1 → Condition 1 < 10 → i != 3 → Print 1
i = 2 → Condition 2 < 10 → i != 3 → Print 2
i = 3 → Condition 3 < 10 → i == 3 → break; (loop terminates)
Final Output:
1
2
Explanation:
The loop runs from i = 0 to i < 10.
When i == 3, the break statement stops the loop, so numbers 3 to 9 are not printed.
Q #include <stdio.h>
main()
int i;
for (i = 0; i< 10; i++)
printf("%d\n", i);
if (i == 3)
continue;
}
ANS Final Output:
Explanation:
The continue; statement normally skips the remaining code in the loop and moves to
the next iteration.
However, since it appears at the end of the loop body, it does not affect the
program's behavior in this case.
The loop still prints numbers from 0 to 9 as expected.
11. Break statement.Write a Program to find the Sum of two numbers entered by
the user.
ANS
Sometimes, it is necessary to exit immediately from loop as soon as the condition is
satisfied.
When break statement is used inside a loop, then it can cause to terminate from a
loop . all statement are skipped.
syntax:- break;
Example 1: Using break in a Loop
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
break; // Exits the loop when i == 3
}
printf("%d\n", i);
}
return 0;
}
#include <stdio.h>
int main() {
int num1, num2, sum;
// Taking input from the user
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
// Calculating sum
sum = num1 + num2;
// Displaying result
printf("Sum = %d\n", sum);
return 0;
}
Q What is the use of a ‘\0’ character?
Ans The \0 (null character) is used to indicate the end of a string in C.
It marks the termination of character arrays (strings) so that functions like printf(),
strlen(), and strcpy() can determine where the string ends.
example:-
#include <stdio.h>
int main() {
char str[] = "Hello"; // Implicitly ends with '\0'
printf("%s\n", str); // Prints "Hello"
char str2[] = {'H', 'e', 'l', 'l', 'o', '\0'}; // Explicitly adding '\0'
printf("%s\n", str2); // Prints "Hello"
return 0;
}
Q . What does static variable mean?
Ans A static variable is a variable that:
Retains its value between function calls.
Has local scope if declared inside a function but persists throughout program
execution.
Is initialized only once (default value: 0 if uninitialized).
Q 14. What are header files and their uses in c?
Ans What are Header Files?
Header files in C contain function declarations, macros, and definitions used in
programs.
They allow code reusability and simplify program structure by separating function
prototypes from implementation.
They have a .h extension, e.g., stdio.h, math.h.
Uses of Header Files:
Provide Standard Library Functions – Functions like printf(), scanf() (in stdio.h) are
defined in header files.
Reduce Code Duplication – Common functions can be written in a header file and
included in multiple programs.
Improve Code Readability – Keeps function declarations separate from
implementation.
Ensure Code Maintainability – Updates in the header file reflect in all files that
include it.
Example of Using a Header File:
Q 15. Define keywords.
Ans:-
In ‘C’ every word can be either a keyword or an identifier.
Keywords have fixed meanings, and the meaning cannot be changed. They act as a
building block of a ‘C’ program. There are a total of 32 keywords in ‘C’. Keywords are
written in lowercase letters.
Following table represents the keywords in ‘C’-
Keywords in C Programming Language
auto double int struct break else long switch case enum register typedef char
extern return union const short float unsigned continue for signed void default goto
sizeof volatile do if static while
Q16 Define Token?
Ans:- TOKEN is the smallest unit in a ‘C’ program. It is each and every word and
punctuation that you come across in your C program. The compiler breaks a program
into the smallest possible units (Tokens) and proceeds to the various stages of the
compilation. C Token is divided into six different types, viz, Keywords, Operators,
Strings, Constants, Special Characters, and Identifiers.
Q 17. What is C character set?
Ans Like every other language, ‘C’ also has its own character set. A program is a set of
instructions that, when executed, generate an output. The data that is processed by a
program consists of various characters and symbols. The output generated is also a
combination of characters and symbols.
A character set in ‘C’ is divided into,
1. Letters
Uppercase characters (A-Z)
Lowercase characters (a-z)
2. Numbers
All the digits from 0 to 9
3. White spaces
Blank space
New line
Carriage return
Horizontal tab
4. Special characters
Special characters in ‘C’ are shown in the given table,
Q 18. Define if-else statement?
if statement in C
if statement is the most simple decision-making statement. It is used to decide whether a
certain statement or block of statements will be executed or not i.e if a certain condition is
true then a block of statement is executed otherwise not.
Syntax:
if(condition)
// Statements to execute if
// condition is true
}
Q. State the basic data types used in ‘C.
Ans C provides several basic data types to store different kinds of values. These are:
Data Type Size (Bytes) Description
int 2 or 4 Stores integers (whole numbers)
float 4 Stores decimal numbers (single precision)
double 8 Stores decimal numbers (double precision)
char 1 Stores a single character
void 0 Represents no value (used for functions)
Q . Explain two dimensional arrays.
Ans Two Dimensional Array in C
The two-dimensional array can be defined as an array of arrays. The 2D array is organized as
matrices which can be represented as the collection of rows and columns. However, 2D
arrays are created to implement a relational database lookalike data structure. It provides
ease of holding the bulk of data at once which can be passed to any number of functions
wherever required.
Declaration of two dimensional Array in C
The syntax to declare the 2D array is given below.
data_type array_name[rows][columns];
Q Define identifier
Ans Definition of Identifier in C
An identifier is the name given to variables, functions, arrays, or other user-defined
elements in a C program. It is used to uniquely identify these entities in the code.
Rules for Identifiers:
1. Can contain letters (A-Z, a-z), digits (0-9), and underscore (_) only.
2. Must begin with a letter or underscore (_), not a digit.
3. Cannot be a C keyword (e.g., int, float).
4. Case-sensitive (e.g., sum and Sum are different).
5. No special characters (*, &, %, etc.) except _ (underscore).
Q Explain Basic structure of C Programming with a diagram.
Ans