BLOG DETAILS

Read the complete blog details covering in-depth explanations, practical insights, and examples. Designed for computer science learners and technology enthusiasts who want clarity, guidance, and knowledge in simple, structured form.

Solved Paper PPL Through C | 2016 | Rajasthan University (RU) | BCA Part-I |

In this blog, we provide the fully solved BCA Part-I Previous Year Question Paper (2016) for the subject Principles of Programming Language through C (PPL through C) conducted by the University of Rajasthan (RU). Every answer is written in simple, easy-to-understand, and exam-oriented language so that students can learn how to write effective answers in the university examination.

Exam Covered: BCA Part-I Examination 2016 (University of Rajasthan)
Subject: Principles of Programming Language through C (Paper-134)

B.C.A. (Part-I) Examination, 2016

Faculty of Science
Three-Year Scheme (10+2+3 Pattern)
Paper-134
Principles of Programming Language (Through C)

Time Allowed: Three Hours

Maximum Marks: 100

Question Paper Pattern

Part-I (Very Short Answer): Consists of 10 questions carrying 2 marks each. The maximum answer length is approximately 40 words.

Part-II (Short Answer): Consists of 5 questions carrying 4 marks each. The maximum answer length is approximately 80 words.

Part-III (Long Answer): Consists of 5 questions carrying 12 marks each with internal choice.

PART – I

  1. Define pseudo code.
  2. What do you understand by machine-level language?
  3. Write the syntax of the switch statement.
  4. What is a header file?
  5. Define an array.
  6. Write the syntax and purpose of strcat().
  7. Why do we use malloc()? Also write its syntax.
  8. Differentiate between local variables and global variables.
  9. Differentiate between a structure and a union.
  10. Write the syntax and purpose of fprintf().

PART – II

  1. Draw a flowchart to find the largest among three numbers.
  2. Explain the different logical operators in C with suitable examples.
  3. Explain the while loop and do-while loop with examples.
  4. Write a C program to calculate the factorial of a number using recursion.
  5. Write any one C function for each of the following:
    1. Opening a file
    2. Closing a file
    3. Reading data from a file
    4. Writing data to a file

PART – III

  1. Write a detailed note on the evaluation of programming languages.
    OR
    Write a pseudo code to generate the following series:
    1. 0, 1, 1, 2, 3, 5, ... n
    2. 1, 4, 9, 16, 25, ... n
  2. Discuss the various decision-making statements in C with suitable examples.
    OR
    Explain the different data types available in C.
  3. What do you understand by iterative statements? Explain the different types of loops supported in C along with the use of break and continue statements.
    OR
    What are arrays? Write a C program to calculate the sum of 10 numbers using an array.
  4. Why do we need user-defined functions? Explain how functions are created in C with suitable examples.
    OR
    What are pointer variables? Write a C program to demonstrate the use of the indirection operator (*) for accessing values through a pointer.
  5. Discuss the formatted and unformatted input/output functions in C.
    OR
    Write a short note on File Handling in C.

Solution – Part I

Let's solve each question one by one in an easy, exam-oriented manner.

Solution – Part I

Instructions: The following solutions are written in simple, exam-oriented language to help students understand the concepts clearly and prepare effectively for university examinations.

Question 1. Define Pseudo Code.

Answer:

A Pseudo Code is an informal way of describing the steps of an algorithm using simple English statements. It resembles a programming language but does not follow the strict syntax rules of any specific language. Pseudo code helps programmers understand the logic of a program before writing the actual source code.

Exam Point: Pseudo code focuses on program logic rather than programming language syntax.

Question 2. What do you understand by Machine-Level Language?

Answer:

Machine-level language is the lowest-level programming language that consists of binary digits (0 and 1). It is directly understood and executed by the computer's processor without requiring any translator such as a compiler or interpreter.

Although machine language executes very quickly, it is difficult for humans to read, write, debug, and maintain because every instruction is represented in binary form.

Exam Point: Machine language is also known as the first-generation programming language (1GL).

Question 3. Write the Syntax of the switch Statement.

Answer:

The switch statement is a multi-way decision-making statement used to execute one block of code from several alternatives based on the value of an expression.

switch(expression)
{
    case constant1:
        statements;
        break;
    case constant2:
        statements;
        break;
    ...
    default:
        statements;
}
Note: The break statement is used to terminate the current case. If no case matches, the default block is executed.

Question 4. What is a Header File?

Answer:

A header file is a file that contains function declarations, macro definitions, constants, and other reusable programming components. Header files allow programmers to use predefined library functions without rewriting their definitions.

In C programming, header files are included in a program using the #include preprocessor directive.

#include <stdio.h>
#include <stdlib.h>
Examples: stdio.h, stdlib.h, string.h, and math.h.

Question 5. Define an Array.

Answer:

An array is a collection of elements of the same data type stored in contiguous memory locations. Each element is accessed using an index, where indexing begins from 0 in C programming.

int marks[5];

The above declaration creates an integer array capable of storing five elements.

Exam Point: Arrays are used to store multiple values of the same data type using a single variable name.

Question 6. Write the Syntax and Purpose of strcat().

Answer:

The strcat() function is used to concatenate (join) one string to the end of another string.

Syntax:

strcat(destination_string, source_string);

The function appends the source string to the destination string and returns the address of the destination string.

Header File: #include <string.h>

Question 7. Why do we use malloc()? Also write its syntax.

Answer:

The malloc() (Memory Allocation) function is used to allocate memory dynamically during program execution. It reserves a specified amount of memory from the heap and returns the address of the first allocated memory block. The allocated memory remains available until it is explicitly released using the free() function.

Syntax:

pointer=(data_type *)malloc(number_of_elements*sizeof(data_type));

Example:

int *ptr;
ptr=(int *)malloc(5*sizeof(int));
Header File: #include <stdlib.h>

Question 8. Differentiate between Local Variables and Global Variables.

Answer:

Local VariableGlobal Variable
Declared inside a function or block.Declared outside all functions.
Accessible only within the function or block where it is declared.Accessible from all functions in the program unless restricted.
Created when the function is called and destroyed when the function ends.Exists throughout the execution of the program.
Has limited scope.Has global scope.
Stored in stack memory.Stored in the data segment of memory.
Exam Point: The main difference between local and global variables is their scope and lifetime.

Question 9. Differentiate between a Structure and a Union.

Answer:

StructureUnion
Each member has its own separate memory location.All members share the same memory location.
All members can store values simultaneously.Only one member can hold a valid value at a time.
The size of a structure is approximately the sum of the sizes of all its members.The size of a union is equal to the size of its largest data member.
Requires more memory.Requires less memory.
Suitable when all data members need to be used together.Suitable when only one data member is used at a time.
Exam Point: Structures provide separate storage for each member, whereas unions allow multiple members to share the same memory location.

Question 10. Write the Syntax and Purpose of fprintf().

Answer:

The fprintf() function is used to write formatted data to a file. It works similarly to the printf() function, but instead of displaying the output on the screen, it writes the formatted output to the specified file.

Syntax:

fprintf(file_pointer,"format_string",variables);

Example:

FILE *fp;
fp=fopen("student.txt","w");
fprintf(fp,"Roll No = %d",101);
fclose(fp);
Header File: #include <stdio.h>

Solution – Part II

In this section, each question carries 4 marks. The answers are explained in a clear and concise manner, making them suitable for university examinations as well as revision purposes.

Question 1. Draw a Flowchart to Find the Largest Among Three Numbers.

Answer:

The following flowchart illustrates the logical steps required to determine the largest number among three given numbers.

Flowchart to Find the Largest Among Three Numbers
Exam Point: The flowchart compares the three input values using decision-making statements and finally displays the largest number.

Question 2. Explain the Different Logical Operators in C with Suitable Examples.

Answer:

Logical operators are used to combine two or more conditions and evaluate whether the overall expression is true or false. They are commonly used in decision-making statements such as if, if-else, while, and for loops.

OperatorNameDescription
&&Logical ANDReturns true only when both conditions are true.
||Logical ORReturns true if at least one condition is true.
!Logical NOTReverses the logical result of a condition.

Example Program

#include <stdio.h>
int main()
{
    int a = 10, b = 20;
    if(a < b && b > 0)
        printf("AND Operator is True\n");
    if(a > b || b > 0)
        printf("OR Operator is True\n");
    if(!(a > b))
        printf("NOT Operator is True\n");
    return 0;
}
Remember: Logical operators always produce either 1 (True) or 0 (False).

Question 3. Explain the while Loop and do-while Loop with Examples.

Answer:

Both while and do-while are looping statements used to execute a block of code repeatedly until a specified condition becomes false. The main difference lies in the point at which the condition is evaluated.

while Loopdo-while Loop
The condition is checked before executing the loop body.The condition is checked after executing the loop body.
The loop may execute zero times if the condition is false initially.The loop executes at least once, even if the condition is false.
Also known as an entry-controlled loop.Also known as an exit-controlled loop.

Syntax of while Loop

while(condition)
{
    // Statements
}

Syntax of do-while Loop

do
{
    // Statements
}
while(condition);
Exam Point: A do-while loop always executes its body at least once because the condition is evaluated after the loop body.

Question 4. Write a C Program to Calculate the Factorial of a Number Using Recursion.

Answer:

A recursive function is a function that calls itself until a terminating condition is satisfied. The following program calculates the factorial of a given number using recursion.

#include <stdio.h>
int factorial(int n)
{
    if(n == 0 || n == 1)
        return 1;
    return n * factorial(n - 1);
}
int main()
{
    int num;
    printf("Enter a Number : ");
    scanf("%d", &num);
    printf("Factorial = %d", factorial(num));
    return 0;
}
Note: The recursive calls continue until the base condition is reached, after which the function starts returning values back to the previous calls.

Question 5. Write Any One C Function for Each of the Following:

Answer:

C provides several built-in functions for performing file operations such as opening, closing, reading, and writing files. Some commonly used functions are listed below.

OperationFunctionDescription
Open a Filefopen()Opens an existing file or creates a new file and returns a file pointer.
Close a Filefclose()Closes an opened file and releases the associated resources.
Read from a Filefscanf()Reads formatted data from a file.
Write to a Filefprintf()Writes formatted data to a file.

Example

#include <stdio.h>
int main()
{
    FILE *fp;
    fp = fopen("student.txt", "w");
    fprintf(fp, "Welcome to Suraku Academy");
    fclose(fp);
    return 0;
}
Note: Always close the file using fclose() after completing file operations. This ensures that all buffered data is written to the file and system resources are released properly.

Solution – Part III

Instructions: Each question in Part III carries 12 marks. Write your answers with proper explanations, diagrams (where applicable), suitable examples, and neatly formatted programs to score maximum marks in the examination.

Question 1. Write a Detailed Note on the Evaluation of Programming Languages.

Answer:

A programming language is evaluated by analyzing different characteristics that determine its usefulness, efficiency, reliability, and ease of programming. A good programming language should be simple to understand, easy to maintain, efficient to execute, and capable of solving a wide variety of problems. These evaluation criteria help programmers select the most suitable language for a particular application.

The major criteria used for evaluating a programming language are explained below.

  • Readability
  • Writability
  • Reliability
  • Cost
  • Portability
  • Efficiency
  • Maintainability
Exam Tip: Questions on the evaluation of programming languages are frequently asked in university examinations. Always explain each evaluation criterion with a brief definition and its importance.

1. Readability

Readability refers to how easily a program can be read and understood by programmers. A language with good readability allows developers to understand the program quickly, making debugging, testing, and maintenance much easier.

The readability of a programming language depends on several factors, including meaningful keywords, simple syntax, consistency, and well-defined language constructs.

Example: Languages such as C, C++, Java, and Python provide meaningful keywords and structured syntax, making programs easier to read and understand.

2. Writability

Writability is the ease with which programmers can develop programs using a programming language. A language with good writability allows programmers to express solutions clearly using fewer statements, thereby improving development speed and reducing programming effort.

Features such as simple syntax, powerful data structures, reusable functions, and modular programming improve the writability of a programming language.

Remember: Higher writability generally increases programmer productivity and reduces the chances of programming errors.

3. Reliability

Reliability refers to the ability of a programming language to produce correct, consistent, and dependable results under different operating conditions. A reliable programming language helps developers create programs that perform accurately with minimal errors.

Reliability depends on factors such as strong type checking, effective exception handling, proper memory management, and overall language design. A highly reliable language reduces unexpected program failures and improves software quality.

Example: Languages such as Java provide automatic memory management and exception handling, which significantly improve the reliability of programs.

4. Cost

Cost is another important criterion used to evaluate a programming language. It represents the overall expense involved in developing, testing, executing, maintaining, and upgrading software throughout its life cycle.

The total cost of a programming language includes programmer training, software development, debugging, maintenance, execution time, hardware requirements, and long-term support. A language that reduces development time and maintenance effort is generally considered more cost-effective.

Exam Point: The overall cost of software development is usually much higher than the initial coding cost. Therefore, maintainability and reliability also influence the total cost.

5. Portability

Portability is the ability of a program to run on different hardware platforms and operating systems with little or no modification. A portable programming language allows the same source code to be compiled and executed on multiple systems.

Portable languages reduce development effort because the same application can be reused across different environments instead of writing separate programs for each platform.

Example: Programs written in C, C++, and Java can generally be executed on different operating systems after recompilation or through a suitable runtime environment.

6. Efficiency

Efficiency measures how effectively a programming language utilizes system resources such as processor time and memory. An efficient language produces programs that execute quickly while consuming minimum memory and computational resources.

Execution speed, optimized memory usage, and efficient compilation are some of the important factors that determine the efficiency of a programming language.

Example: C is widely regarded as one of the most efficient programming languages because it provides direct memory access and produces fast executable programs.

7. Maintainability

Maintainability is the ease with which an existing program can be modified, corrected, enhanced, or updated after its development. Software often requires maintenance to fix errors, improve performance, or add new features.

A programming language with clear syntax, modular programming support, meaningful identifiers, and proper documentation makes software maintenance much easier and less time-consuming.

Remember: Good readability and modular program design greatly improve the maintainability of software.

Summary of Programming Language Evaluation Criteria

Evaluation CriterionDescription
ReadabilityEase of reading and understanding a program.
WritabilityEase of writing programs using the language.
ReliabilityAbility to produce accurate and dependable results.
CostTotal expense involved in software development and maintenance.
PortabilityAbility to run programs on different platforms.
EfficiencyEffective utilization of processor time and memory.
MaintainabilityEase of modifying and updating existing software.
Quick Revision: A good programming language should be easy to read, easy to write, reliable, cost-effective, portable, efficient, and easy to maintain. These characteristics are commonly used to compare and evaluate different programming languages.

OR

Write a Pseudo Code to Generate the Following Series:

  1. 0, 1, 1, 2, 3, 5, ... n
  2. 1, 4, 9, 16, 25, ... n

Answer: The solutions for both series are given below using simple pseudo code.

(a) Pseudo Code to Generate the Fibonacci Series

The Fibonacci series is a sequence in which each number is obtained by adding the two preceding numbers. The series begins with 0 and 1.

BEGIN
INPUT n
SET first = 0
SET second = 1
PRINT first, second
FOR i = 3 TO n
    SET next = first + second
    PRINT next
    SET first = second
    SET second = next
END FOR
END
Output Series: 0, 1, 1, 2, 3, 5, 8, 13, ...

(b) Pseudo Code to Generate the Series 1, 4, 9, 16, 25, ... n

This series represents the square of natural numbers. Each term is obtained by multiplying the number by itself.

BEGIN
INPUT n
FOR i = 1 TO n
    PRINT i × i
END FOR
END
Output Series: 1, 4, 9, 16, 25, 36, 49, ...

Question 2. Discuss the Various Decision-Making Statements in C with Suitable Examples.

Answer:

Decision-making statements enable a program to execute different blocks of code based on whether a specified condition evaluates to true or false. They play a vital role in controlling the flow of program execution and are widely used in C programming.

The commonly used decision-making statements in C are listed below.

StatementDescription
ifExecutes a block of code only when the specified condition is true.
if...elseChooses between two alternative blocks depending on the condition.
Nested ifUses one if statement inside another if statement for multiple conditions.
else-if LadderChecks multiple conditions one after another until a matching condition is found.
switchSelects one block of code from multiple alternatives based on the value of an expression.

1. if Statement

The if statement executes a block of code only when the specified condition is true.

if(condition)
{
    // Statements
}

2. if...else Statement

The if...else statement is used when one block should execute if the condition is true and another block should execute if the condition is false.

if(condition)
{
    // Statements
}
else
{
    // Statements
}

3. Nested if Statement

A nested if statement contains one if statement inside another. It is useful when multiple conditions need to be checked in sequence.

if(condition1)
{
    if(condition2)
    {
        // Statements
    }
}

4. else-if Ladder

The else-if ladder is used to test several conditions one after another. As soon as one condition becomes true, the corresponding block is executed and the remaining conditions are skipped.

if(condition1)
{
    // Statements
}
else if(condition2)
{
    // Statements
}
else
{
    // Statements
}

5. switch Statement

The switch statement provides an efficient way to select one block of code from several alternatives based on the value of an expression.

switch(expression)
{
    case value1:
        // Statements
        break;
    case value2:
        // Statements
        break;
    default:
        // Statements
}
Exam Point: The switch statement is generally preferred over multiple if...else statements when checking the value of a single variable against several constant values.

OR

Explain the Different Data Types Available in C.

Answer:

A data type specifies the type of data that a variable can store in a C program. It also determines the amount of memory allocated to the variable and the range of values it can hold. Selecting an appropriate data type helps in efficient memory utilization and accurate program execution.

The major data types available in C are explained below.

Data TypeExampleDescription
intint a = 10;Used to store integer values without decimal points.
floatfloat x = 12.5;Used to store single-precision decimal (floating-point) values.
doubledouble y = 25.56789;Used to store double-precision floating-point values with higher accuracy.
charchar ch = 'A';Used to store a single character.
voidvoid display();Represents the absence of a value or return type.

Classification of Data Types in C

Data types in C can be broadly classified into the following categories.

CategoryExamples
Basic (Primary) Data Typesint, char, float, double, void
Derived Data TypesArrays, Pointers, Functions
User-Defined Data Typesstruct, union, enum, typedef
Note: Basic data types are provided by the C language itself, whereas user-defined data types allow programmers to create customized data structures according to application requirements.
Exam Point: Questions related to C data types often ask students to classify them and explain their purpose with suitable examples.

Question 3. What Do You Understand by Iterative Statements? Explain the Different Types of Loops Supported in C Along with the Use of break and continue Statements.

Answer:

Iterative statements, also known as looping statements, are used to execute a block of code repeatedly until a specified condition becomes false. Loops help eliminate repetitive coding and make programs more efficient, readable, and easier to maintain.

C programming supports three types of loops:

  • while Loop
  • do...while Loop
  • for Loop

1. while Loop

The while loop checks the condition before executing the loop body. Therefore, it is known as an entry-controlled loop.

while(condition)
{
    // Statements
}

2. do...while Loop

The do...while loop executes the statements first and checks the condition afterward. As a result, the loop body executes at least once regardless of whether the condition is true or false.

do
{
    // Statements
}
while(condition);

3. for Loop

The for loop is commonly used when the number of iterations is known in advance. It combines initialization, condition checking, and increment/decrement into a single statement.

for(initialization;condition;increment)
{
    // Statements
}
Quick Revision:
  • while ? Entry-controlled loop.
  • do...while ? Exit-controlled loop.
  • for ? Best suited when the number of iterations is predetermined.

Use of the break Statement

The break statement is used to terminate a loop or a switch statement immediately. Once a break statement is encountered, the control exits the loop or switch block and continues with the next statement following it.

for(int i = 1; i <= 10; i++)
{
    if(i == 5)
        break;
    printf("%d ", i);
}
Output: 1 2 3 4

Use of the continue Statement

The continue statement is used to skip the remaining statements of the current iteration and immediately move to the next iteration of the loop. Unlike the break statement, it does not terminate the loop.

for(int i = 1; i <= 5; i++)
{
    if(i == 3)
        continue;
    printf("%d ", i);
}
Output: 1 2 4 5
Exam Point:
  • break immediately terminates the loop.
  • continue skips the current iteration and proceeds to the next iteration.
  • Both statements are commonly used with for, while, and do...while loops.

OR

What are Arrays? Write a C Program to Calculate the Sum of 10 Numbers Using an Array.

Answer:

An array is a collection of elements of the same data type stored in contiguous memory locations. Each element is identified by an index, with indexing starting from 0 in C programming.

Arrays make it easy to store and process multiple values using a single variable name. They are widely used for handling collections of similar data efficiently.

Syntax

data_type array_name[size];

Example

int marks[10];

The above declaration creates an integer array capable of storing 10 integer values.

C Program to Calculate the Sum of 10 Numbers Using an Array

#include <stdio.h>
int main()
{
    int arr[10];
    int i, sum=0;
    printf("Enter 10 Numbers:\n");
    for(i = 0;i < 10;i++)
    {
        scanf("%d",&arr[i]);
        sum=sum+arr[i];
    }
    printf("Sum : %d",sum);
    return 0;
}
Working: The program first stores ten numbers in an array using a for loop. During the same loop, each element is added to the variable sum. Finally, the total sum of all ten numbers is displayed.
Exam Point: Arrays allow multiple values of the same data type to be stored under a single variable name, making programs simpler and more efficient.

Question 4. Why Do We Need User-Defined Functions? Explain How Functions Are Created in C with Suitable Examples.

Answer:

A user-defined function is a function created by the programmer to perform a specific task. Instead of writing the same code repeatedly, the required statements are placed inside a function and can be called whenever needed. This makes programs modular, reusable, easier to understand, and easier to maintain.

User-defined functions improve code readability, reduce duplication, simplify debugging, and make large programs easier to manage.

Benefits of User-Defined Functions:
  • Promote code reusability.
  • Reduce program complexity.
  • Improve readability and maintainability.
  • Simplify testing and debugging.
  • Support modular programming.

Steps to Create a User-Defined Function in C

Creating a user-defined function in C involves three important steps:

  1. Function Declaration (Function Prototype)
  2. Function Definition
  3. Function Call

1. Function Declaration

A function declaration informs the compiler about the function's name, return type, and parameters before it is used in the program.

return_type function_name(parameter_list);

Example:

int add(int, int);

2. Function Definition

A function definition contains the actual statements that perform the required task.

int add(int a,int b)
{
    return a+b;
}

3. Function Call

A function call transfers program control to the function so that it can execute the required operations and, if applicable, return a result to the calling function.

result = add(10,20);

Example Program

#include <stdio.h>
int add(int, int);
int main()
{
    int sum;
    sum = add(10, 20);
    printf("Sum = %d", sum);
    return 0;
}
int add(int a,int b)
{
    return a+b;
}
Explanation: The program defines a user-defined function named add() that accepts two integer values, calculates their sum, and returns the result to the main() function.
Exam Point: Every user-defined function generally consists of a function declaration, a function definition, and a function call.

OR

What are Pointer Variables? Write a C Program to Demonstrate the Use of the Indirection Operator (*) for Accessing Values Through a Pointer.

Answer:

A pointer variable is a special type of variable that stores the memory address of another variable instead of storing the actual value. Pointers are widely used for dynamic memory allocation, passing arguments to functions, efficient array processing, and implementing complex data structures such as linked lists, stacks, queues, and trees.

The indirection operator (*), also known as the dereference operator, is used to access the value stored at the memory address contained in a pointer.

Syntax of Pointer Declaration

data_type *pointer_name;

Example:

int *ptr;

C Program to Demonstrate the Use of the Indirection Operator

#include <stdio.h>
int main()
{
    int num=100;
    int *ptr;
    ptr=&num;
    printf("Value of num = %d\n", num);
    printf("Address of num = %p\n", &num);
    printf("Value stored in ptr = %p\n", ptr);
    printf("Value using *ptr = %d\n", *ptr);
    return 0;
}
Explanation: The pointer ptr stores the address of the variable num. Using the dereference operator (*ptr), the program accesses the value stored at that memory location without directly referring to the variable name.
Exam Point:
  • The & (address-of) operator returns the memory address of a variable.
  • The * (dereference) operator accesses the value stored at the memory address held by a pointer.
  • A pointer stores an address, whereas the dereference operator retrieves the value stored at that address.

Question 5. Discuss the Formatted and Unformatted Input/Output Functions in C.

Answer:

Input and output operations in C are broadly classified into formatted input/output and unformatted input/output. These functions enable communication between the user and the program by accepting input and displaying output.

Formatted Input/Output Functions

Formatted input/output functions allow data to be entered or displayed in a specific format using format specifiers such as %d, %f, %c, and %s. These functions are commonly used when working with different data types in C.

FunctionDescription
printf()Displays formatted output on the screen.
scanf()Reads formatted input from the keyboard.
fprintf()Writes formatted output to a file.
fscanf()Reads formatted input from a file.
sprintf()Stores formatted output in a string.
sscanf()Reads formatted data from a string.

Example

#include <stdio.h>
int main()
{
    int age;
    printf("Enter Your Age: ");
    scanf("%d", &age);
    printf("Age = %d", age);
    return 0;
}
Note: Formatted input/output functions use format specifiers to read and display different types of data accurately.

Unformatted Input/Output Functions

Unformatted input/output functions read or display data without using format specifiers. These functions are generally used for handling single characters or strings and are simpler than formatted input/output functions.

FunctionDescription
getchar()Reads a single character from the keyboard.
putchar()Displays a single character on the screen.
gets()Reads an entire string from the keyboard. (Deprecated in modern C)
puts()Displays a string on the screen.

Example

#include <stdio.h>
int main()
{
    char ch;
    printf("Enter a Character: ");
    ch = getchar();
    printf("You Entered: ");
    putchar(ch);
    return 0;
}
Important: The gets() function is deprecated because it does not perform boundary checking and may cause buffer overflow. In modern C programming, fgets() is recommended as a safer alternative.
Quick Revision:
  • Formatted Functions: printf(), scanf(), fprintf(), fscanf(), sprintf(), and sscanf().
  • Unformatted Functions: getchar(), putchar(), gets(), and puts().
  • Formatted functions use format specifiers, whereas unformatted functions do not.

OR

Write a Short Note on File Handling in C.

Answer:

File handling in C is the process of storing, retrieving, and managing data in files on secondary storage devices such as hard disks or SSDs. It allows data to be saved permanently so that it remains available even after the program terminates.

C provides a set of standard library functions to perform various file operations such as creating, opening, reading, writing, appending, and closing files. These functions are declared in the <stdio.h> header file.

Basic Steps in File Handling

  1. Create or open a file using fopen().
  2. Perform the required read or write operations.
  3. Close the file using fclose().
Header File: #include <stdio.h>

Common File Opening Modes in C

Different file opening modes are available in C depending on the operation to be performed. The mode specified in the fopen() function determines whether a file will be created, read, written, or updated.

ModeDescription
"r"Opens an existing file for reading. The file must already exist.
"w"Opens a file for writing. If the file already exists, its contents are overwritten. If it does not exist, a new file is created.
"a"Opens a file in append mode. New data is added at the end of the file without removing the existing contents.
"r+"Opens an existing file for both reading and writing.
"w+"Opens a file for both reading and writing. If the file exists, its contents are overwritten; otherwise, a new file is created.
"a+"Opens a file for both reading and appending. New data is always written at the end of the file.

Common File Handling Functions

The following standard library functions are frequently used while performing file operations in C.

FunctionDescription
fopen()Opens an existing file or creates a new file.
fclose()Closes an opened file.
fprintf()Writes formatted data to a file.
fscanf()Reads formatted data from a file.
fgetc()Reads a single character from a file.
fputc()Writes a single character to a file.
fgets()Reads a string from a file.
fputs()Writes a string to a file.

Example Program

The following program demonstrates how to create a file, write data into it, and then close the file.

#include <stdio.h>
int main()
{
    FILE *fp;
    fp = fopen("student.txt", "w");
    if(fp == NULL)
    {
        printf("Unable to Open File");
        return 1;
    }
    fprintf(fp, "Welcome to Suraku Academy");
    fclose(fp);
    printf("Data Written Successfully.");
    return 0;
}
Explanation: The program creates a file named student.txt in write mode using fopen(). The fprintf() function writes data into the file, and finally fclose() closes the file and releases the associated system resources.
Important: Always verify whether fopen() successfully opens the file before performing any file operation. If it returns NULL, it indicates that the file could not be opened.
Quick Revision:
  • Use fopen() to open or create a file.
  • Use fprintf(), fscanf(), fgetc(), fputc(), fgets(), and fputs() to perform file operations.
  • Always close the file using fclose() after completing all operations.
  • Check whether the returned file pointer is NULL before reading from or writing to a file.

Conclusion

This article presented the fully solved BCA Part-I (2016) Previous Year Question Paper for the subject Principles of Programming Language through C. Each question has been explained in simple, exam-oriented language with appropriate examples, tables, and C programs to help students understand the concepts more effectively.

Practicing previous year question papers is one of the most effective ways to understand the examination pattern, identify important topics, and improve answer-writing skills. Regular practice also builds confidence and helps students perform better in university examinations.

Keep Learning!

Continue solving previous year question papers and practicing C programming regularly. Consistent practice will strengthen your programming concepts and improve your performance in university exams, competitive examinations, and technical interviews.

Suresh Kulahry

About the Author

Suresh Kulahry

Suresh Kulahry is the Founder of Suraku Academy and an educator dedicated to helping students prepare for Computer Science examinations through simple explanations, high-quality study material, MCQs, Previous Year Questions, and practical tutorials. His mission is to make computer science learning easy, accessible, and free for every learner.

🎉 Thank You for Reading!

We hope this article helped you understand the topic better. Continue your Computer Science preparation with more free resources available on Suraku Academy.