Data types and variables
- Floating-Point Types: float, double, long double
structure of a c program
The basic parts of c program:
The structure of a typical C program consists of several components that are arranged in a specific order. Here is the general structure of a C program:
1. Preprocessor Directives:
The program may begin with preprocessor directives, indicated by the '#' symbol. These directives are used to include header files or define constants that are needed for the program.
2. Global Declarations:
Following the preprocessor directives, global variable and function declarations can be included. Global variables are accessible throughout the program, while function declarations provide information about functions that will be defined later in the program.
3. Main Function:
Every C program must have a main function, which serves as the entry point for program execution. The main function is where the program's instructions are written.
4. Variable Declarations:
Inside the main function, variables can be declared. These variables are used to store data that will be manipulated or used in the program.
5. Statements and Expressions:
The main body of the program consists of statements and expressions. Statements perform actions or control the flow of execution, while expressions compute values or perform calculations.
6. Function Definitions:
In addition to the main function, other functions may be defined within the program. These functions can be called from the main function or other functions to perform specific tasks.
7. Return Statement:
At the end of the main function or any other function, a return statement can be used to specify the value that the function should return to the calling function. The return statement is optional in the main function but required in other functions with non-void return types.
Sample of C program:
Here is a simplified example of a C program structure:
//my first program in C
#include <stdio.h>
// Global variable declaration
int globalVariable;
// Function declaration
void someFunction();
// Main function
int main() {
// Variable declarations
int localVariable;
// Statements and expressions
printf("Hello, World!\n");
// Call another function
someFunction();
// Return statement
return 0;
}
// Function definition
void someFunction() {
// Function body
// ...
}
It's important to note that this structure provides a basic framework for organizing a C program, but the specific implementation and complexity can vary depending on the requirements of the program.
how to set up C environment
How to set up C coding environment
Features of C
Important features of C language are listed below.
1. Simplicity:
C has a relatively simple and minimalistic syntax, making it easy to learn and understand. It has a small set of keywords and a straightforward structure, which contributes to its readability and maintainability.
2. Efficiency:
C is known for its efficiency in terms of execution speed and memory usage. It allows direct memory manipulation and provides low-level control over hardware resources. C programs can be optimized for performance, making it suitable for developing applications with strict resource constraints or performance requirements.
3. Portability:
C code can be compiled and executed on different platforms and operating systems with minimal modifications. The language is designed to be machine-independent, with a focus on abstracting away hardware-specific details. This portability is facilitated by the use of compilers that generate machine code specific to the target platform.
4. Modularity:
C supports modular programming through the use of functions and libraries. Programs can be divided into smaller, reusable modules, making them easier to develop, understand, and maintain. C libraries provide a wide range of pre-written functions that can be included in programs, reducing the need to reinvent common functionalities.
5. Low-level Features:
C allows direct manipulation of memory addresses and provides features like pointers, which enable efficient memory management and data structures. This low-level control is particularly useful in system programming, embedded systems, and device drivers.
6. Flexibility:
C supports both procedural and structured programming paradigms. It allows programmers to organize code into functions and control structures like loops and conditionals. Additionally, C can be used for object-oriented programming (OOP) with the help of additional libraries like C++ or Objective-C.
7. Extensibility:
C allows programmers to extend the language through the use of libraries and user-defined functions. This enables the creation of custom functionalities and the integration of C code with other programming languages.
8. Standardized:
The C language has a standardized syntax and semantics defined by ANSI (American National Standards Institute) and ISO (International Organization for Standardization). These standards ensure compatibility and portability of C code across different platforms and compilers.
9. Wide Usage and Support:
C has a large and active community of developers, making it easy to find resources, libraries, and support. There are numerous textbooks, online tutorials, forums, and open-source projects available to help programmers learn and work with C.
These features contribute to the popularity and versatility of the C programming language, making it a powerful choice for a wide range of applications, including system programming, embedded systems, game development, scientific computing, and more.
---------------------------------------------------------------------------------------------------------------
Previous Next
History of C language
Who developed C language?
Dennis Ritchi
The history of the C programming language dates back to the early 1970s. C was developed by Dennis Ritchie at Bell Labs (formerly AT&T Bell Laboratories) as a successor to the B programming language. Ritchie initially created C to aid in the development of the Unix operating system, which was also being developed at Bell Labs.
BCPL language:-
The roots of C can be traced back to an earlier programming language called BCPL (Basic Combined Programming Language), which was developed by Martin Richards in the mid-1960s. BCPL influenced the development of B, which in turn laid the foundation for C. Ritchie and Ken Thompson, another Bell Labs researcher, had previously worked on the development of the Multics operating system using BCPL and saw the need for a more efficient and portable language.
In 1972, Ritchie made significant enhancements to the B language, adding data types, operators, and other features, and renamed it C. The name "C" was chosen because it followed the alphabetical progression from B, and also because many of its features were derived from an earlier language called CPL (Combined Programming Language).
Development of unix Operating system using C language:-
C gained popularity within Bell Labs and was used extensively for the development of the Unix operating system. The ability to write efficient and portable code in C played a significant role in the widespread adoption of Unix. As Unix began to gain popularity in the late 1970s and early 1980s, the use of C spread beyond Bell Labs, and programmers from other organizations started embracing the language.
In 1978, the first edition of "The C Programming Language" book, written by Brian Kernighan and Dennis Ritchie (commonly known as K&R C), was published. This book became the authoritative reference for the C language and helped solidify its popularity. It provided clear explanations and examples of the language's features and coding techniques.
The influence of C continued to grow in the 1980s. In 1983, the American National Standards Institute (ANSI) established a committee to standardize the C language, resulting in the ANSI C standard in 1989. This standard, often referred to as C89 or C90, helped ensure the portability of C code across different platforms.
In 1990, an updated version of the C standard, known as C99, was published. C99 introduced several new features and improvements to the language, including support for inline functions, variable-length arrays, and new data types.
In recent years, the C language has remained widely used and influential. Its simplicity, efficiency, and portability continue to make it a preferred choice for system programming, embedded systems, and various other applications. The C programming language has also served as the foundation for other languages, such as C++, Objective-C, and C#.
Introduction to C
C is a widely-used and influential programming language known for its efficiency and versatility. It was developed in the early 1970s by Dennis Ritchie at Bell Labs as a successor to the B programming language. C was initially designed to facilitate system programming and to provide a higher-level alternative to assembly language.
Key features of the C language include its low-level nature, which allows direct memory manipulation and efficient hardware access, as well as its simple syntax and structured programming constructs. C provides a balance between high-level abstraction and low-level control, making it suitable for a wide range of applications, including operating systems, embedded systems, device drivers, game development, and scientific computing.
C has a small set of keywords and operators, making it relatively easy to learn. It supports essential programming constructs such as variables, data types, control flow statements (if-else, loops), functions, arrays, and pointers. These features provide the foundation for building complex programs and data structures.
One of the strengths of C is its portability. C programs can be compiled and run on various platforms, including Windows, macOS, Linux, and even embedded systems like microcontrollers. This portability is achieved by separating the language itself from the underlying hardware, making C a "machine-independent" language.
Another important aspect of C is its close relationship with the operating system. C allows direct access to memory and hardware resources, making it suitable for system-level programming. It provides features like pointers and structures, which enable efficient memory management and manipulation.
C has influenced the development of numerous other programming languages, including C++, Java, C#, and Objective-C. Many popular software applications and operating systems, such as the Unix operating system and the Linux kernel, have been written in C.
Overall, C is a powerful and flexible programming language that offers a fine-grained control over the hardware, making it a preferred choice for systems programming and performance-critical applications. Its simplicity, efficiency, and wide range of applications have contributed to its enduring popularity among programmers.
HISSAN grade 12 computer science question 2079
HISSAN CENTRAL
EXAMINATION - 2079 (2023)
Grade: XII Time:
2 hrs
Subject:- COMPUTER
SCIENCE (TH) [4281 A] Full
Marks: 50
GROUP A [9×1=9]
Multiple Choice Questions.
Choose the correct answer.
1. In which normal form of database transitive dependency should not be occurred?
A)
First
B) second
C) Third
d) All of above
2. Which of the following techniques is used to grant privileges to user in a database?
A)
Authentication
B) Authorization
C) Isolation
D) Backup
3. Which SQL command is used to display all the records from a table named STUDENT with "H" as the first letter in the field FNAME (FIRST NAME)?
A) SELECT * FROM STUDENT WHERE FNAME LIKE "H";
B) SELECT * FROM STUDENT WHERE FNAME LIKE "%H%";
C) SELECT * FROM STUDENT WHERE FNAME LIKE "H%";
D) SELECT * FROM STUDENT WHERE FNAME LIKE "H";
4. Which of the following is a remote login service?
A) FTP
B)Telnet
C) SMTP
5. Which of the following is a server-side scripting language?
A)
PHP
B) MySql
C) JavaScript
D) SQL
6. Which of the following keywords are used to declare a variable in JavaScript?
A) int or suppose
B) float or int
C) var or let
D) char or var
7. What will be the result of combining a string with another data type in PHP?
A)
Float
B) int
C) string
D) double
8. The process of hiding internal details of a program and exposing the functionality is .....
A) Class.
B) Polymorphism.
C) Inheritance
D) Data Abstraction.
9. Which of the following is not a phase of SDLC?
A) Analysis.
B) Developing
C) Testing
D) Meeting
GROUP B [5x5=25]
Short Answer Questions
10. Suppose you are appointed as an IT expert in a Hotel. What kind of database system you preferred and why? [1+4]
OR
Most of the Hospitals prefer applying a relational database model for database design compared to other models. Justify the statement with your arguments. [5]
11. Write a program in JavaScript to add the values of any two variables. [5]
OR
How can you connect MYSQL database with PHP? Demonstrate with an example. [5]
12. Differentiate between OOP and procedural oriented language. [5]
13. State various stages of SDLC and explain any two. [5]
14. Explain mobile computing with advantages. [1+2+2]
GROUP C [2x8=16]
Long Answer Questions
15. Suppose you are appointed as an IT expert of any bank which network architecture you prefer and why? [2+6]
16. Write a program in C using structure to enter the roll_number, name, and marks scored in english, computer, maths and nepali of 10 students. Also, display them in proper format along with the total
marks. [Note: the marks should be between 0 and 100]. [8]
OR
Write a program in C to
create and store name, gender, and phoneno of students to a data file named
"ADDRESS.DAT". The program should prompt the user whether to continue
or not. The program should also display all the records in the proper format. [8]
THE END
-----------------------------------------------------------------------------------------------------------
Answer key:
1.) c 2).B 3.) C 4.) D 5.) A 6.) C 7) C 8.)D 9.) D
--------------------------------------------------------------------------------------------------------------
Solutions:
HISSAN CENTRAL EXAMINATION - 2079 (2023)
Grade: XII Time: 2 hrs
Subject:- COMPUTER SCIENCE (TH) [4281 A] Full Marks: 50
GROUP A [9×1=9]
Multiple Choice Questions.
Choose the correct answer.
1. In which normal form of database transitive dependency should not be occurred?
A) First
B) second
C) Third
d) All of above
2. Which of the following techniques is used to grant privileges to user in a database?
A) Authentication
B) Authorization
C) Isolation
D) Backup
3. Which SQL command is used to display all the records from a table named STUDENT with "H" as the first letter in the field FNAME (FIRST NAME)?
A) SELECT * FROM STUDENT WHERE FNAME LIKE "H";
B) SELECT * FROM STUDENT WHERE FNAME LIKE "%H%";
C) SELECT * FROM STUDENT WHERE FNAME LIKE "H%";
D) SELECT * FROM STUDENT WHERE FNAME LIKE "H";
4. Which of the following is a remote login service?
A) FTP
B)Telnet
C) SMTP
5. Which of the following is a server-side scripting language?
A) PHP
B) MySql
C) JavaScript
D) SQL
6. Which of the following keywords are used to declare a variable in JavaScript?
A) int or suppose
B) float or int
C) var or let
D) char or var
7. What will be the result of combining a string with another data type in PHP?
A) Float
B) int
C) string
D) double
8. The process of hiding internal details of a program and exposing the functionality is .....
A) Class.
B) Polymorphism.
C) Inheritance
D) Data Abstraction.
9. Which of the following is not a phase of SDLC?
A) Analysis.
B) Developing
C) Testing
D) Meeting
GROUP B [5x5=25]
Short Answer Questions
10. Suppose you are appointed as an IT expert in a Hotel. What kind of database system you preferred and why?
Ans:-
-
Structured Data Storage:
Hotel operations involve structured data like guest records, room bookings, billing, inventory, staff details, etc. RDBMS stores this data in well-organized tables with clear relationships. -
Data Integrity and Accuracy:
RDBMS supports constraints and data validation, ensuring data accuracy (e.g., no duplicate bookings or invalid guest entries). -
Easy Querying and Reporting:
Using SQL, we can quickly generate reports like available rooms, guest check-ins, or billing summaries, helping in fast decision-making. -
Multi-user Access:
Multiple departments (reception, kitchen, housekeeping, accounts) can access and update data simultaneously without conflicts. -
Security and Backup:
RDBMS provides user roles and permissions, securing sensitive data. It also supports regular backups and recovery options.
[1+4]
OR
Most of the Hospitals prefer applying a relational database model for database design compared to other models. Justify the statement with your arguments.
Ans:-
Most hospitals prefer using the Relational Database Model (RDBMS) for database design due to the following strong reasons:
1. Structured and Organized Data Storage
Hospitals deal with structured data such as patient records, doctor information, lab reports, billing, appointments, etc. The relational model allows storing this data in tables with rows and columns, making it easy to manage and retrieve.
2. Data Integrity and Accuracy
RDBMS supports primary keys, foreign keys, and constraints, ensuring that data is consistent, accurate, and free from duplication. For example, each patient has a unique ID, and their test reports or prescriptions are linked properly.
3. Easy Data Retrieval Using SQL
RDBMS supports Structured Query Language (SQL), which helps hospital staff retrieve and analyze data quickly — like finding patient history, generating reports, or checking doctor schedules.
4. Security and Role-Based Access
Relational databases provide user roles and permissions to control who can view or modify data. This is crucial in hospitals where patient data privacy and data security are highly important.
5. Multi-user and Concurrent Access
Multiple departments (e.g., OPD, billing, pharmacy, lab) can access and update the same database simultaneously without conflicts, making hospital operations smoother and more efficient.
6. Scalability and Maintenance
As hospital data grows over time, relational databases can easily scale and be maintained. Tables can be added or modified without affecting existing data relationships. [5]
11. Write a program in JavaScript to add the values of any two variables. [5]
Ans:-
<script>
let a = 10;
let b = 20;
let sum = a + b;
console.log("The sum of a and b is: " + sum);
OR
How can you connect MYSQL database with PHP? Demonstrate with an example. [5]
Ans:-
The mysqli_connect()
function is used to establish a connection to a MySQL database using the MySQLi (MySQL Improved) extension in PHP.
Syntax:
mysqli_connect(host, username, password, database, port, socket);
Parameter | Description |
---|---|
host | The hostname or IP address of the MySQL server (e.g., "localhost" ). |
username | MySQL username (e.g., "root" ). |
password | Password for the MySQL user. Mostly it is empty. |
database | Name of the database to connect to. |
Example: |
$connection = mysqli_connect("localhost", "root", "", "school");
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
12. Differentiate between OOP and procedural oriented language. [5]
Ans:-
Procedural Oriented Language(POP):-
Procedure oriented programming basically consists of writing a list of instructions(or actions) for the computer to follow, and organizing these instructions into groups known as functions. While we concentrate on the development , very little attention is given to the data that are being used by various functions.
Diagrammatically we can show POP as
Some characteristics (features) of Procedure Oriented Programming are :-
1) Emphasis is on doing things(algorithms).
2) Large programs are divided into smaller programs known as functions.
3) Most of the functions share global data.
4) Data more openly around the system from function to function.
5) Functions transform data from one form to another.
6) Employs a top-down approach in program design.
OOP(Object Oriented Programming):-
The major motivating factor in the invention of object oriented is to remove some of the flaws encountered in the procedural oriented approach. Object oriented programming uses concept of “Object” and treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it, and protects it from accidental modifications from outside functions.
Some characteristics (features) of Object Oriented Programming are :-
1) Emphasis is on data rather than procedures or algorithms.
2) Programs are divided into what are known as objects.
3) Data structures are designed such that characterize the objects.
4) Functions that operate on the data are tied together in the data structure.
5) Data is hidden and cannot be accessed by external functions.
6) Objects may communicate with each other through functions.
7) New data and functions can be easily added whenever necessary.
8) Follows bottom-up approach in program design.
13. State various stages of SDLC and explain any two. [5]
Ans:-
The Software Development Life Cycle (SDLC) consists of several phases that guide the process of developing high-quality software. The main stages are:
Requirement gathering/planning
-
Requirement Analysis
-
System Design
development(coding)
Testing
-
Implementation /deployment
-
Maintenance
Here's a brief explanation of Analysis and Development phases in SDLC:
Analysis Phase:
In the analysis phase, the goal is to understand the exact requirements of the software system. This involves gathering information from clients or users to identify what the system should do. The result is a requirement specification document that guides the rest of the development process.
Development (Implementation) Phase:
In the development phase, the actual coding of the software takes place. Based on the design documents, developers write code using suitable programming languages. This is where the system starts to take shape as a working product.
14. Explain mobile computing with advantages. [1+2+2]
Ans:-
Mobile computing:-
Mobile computing refers to the ability to use computing devices such as smartphones, tablets, and laptops wirelessly and on-the-go, allowing users to access data and perform tasks without being tied to a fixed location.
Some advantages of mobile computing are:
Advantages of Mobile Computing:
-
Increased Flexibility:
Users can access applications, data, and services from any location, allowing them to work remotely and manage tasks on the go. -
Real-time Communication:
Mobile computing allows for instant communication through emails, messaging apps, and video calls, which is crucial for quick decision-making and collaboration. -
Improved Productivity:
Mobile devices like smartphones and tablets allow users to complete tasks and access information quickly, helping professionals stay productive even while traveling or outside the office. -
Cost Efficiency:
Mobile computing reduces the need for physical office setups and infrastructure, as employees can work remotely, leading to lower operational costs for businesses.
GROUP C [2x8=16]
Long Answer Questions
15. Suppose you are appointed as an IT expert of any bank which network architecture you prefer and why? [2+6]
Ans:-
If I were appointed as an IT expert for a bank, I would prefer the Client-Server Architecture for the bank's network. This is a widely used and suitable architecture for banks due to its security, scalability, and efficient management.
Reasons for Preferring Client-Server Architecture are:
1.Centralized Management:
Client-Server architecture allows for centralized control over all data and applications. The bank’s critical data (such as transaction records, account details, etc.) is stored on secure, centralized servers, making it easier to manage and backup information efficiently.
2.Data Security:
Banks deal with sensitive financial data. In a client-server setup, data access can be strictly controlled and monitored. Security protocols like firewalls, encryption, and access control mechanisms can be implemented at the server level to ensure safe transmission and storage of customer data.
3.Scalability:
The Client-Server architecture supports easy scalability. As the bank grows or experiences more traffic, the system can be expanded by adding more servers or upgrading server capacity to meet increased demands without disrupting services.
4.Reliable Communication and Data Flow:
Client-server systems ensure that client devices (e.g., ATMs, desktop terminals) securely interact with the central server, ensuring fast and reliable data processing. For example, a customer’s request at an ATM or bank terminal will be processed efficiently by the server.
5.High Availability and Redundancy:
Banks cannot afford downtime. With multiple servers and redundant systems, client-server architecture ensures high availability and backup servers in case of failure, ensuring uninterrupted banking services.
6.Easy Maintenance and Updates:
Updates and maintenance are easier to implement in a client-server model because the server is the centralized hub. Software updates, security patches, and new features can be deployed on the server and automatically reflected on all client devices, reducing operational complexity.
16. Write a program in C using structure to enter the roll_number, name, and marks scored in english, computer, maths and nepali of 10 students. Also, display them in proper format along with the total
marks. [Note: the marks should be between 0 and 100]. [8]
Ans:-
#include <stdio.h>
#include <string.h>
#define STUDENTS 10
struct Student
{
int roll_number;
char name[50];
int english;
int computer;
int maths;
int nepali;
int total;
};
int main()
{
struct Student s[STUDENTS];
for (int i = 0; i < STUDENTS; i++) {
printf("\nEnter details for Student %d:\n", i + 1);
printf("Roll Number: ");
scanf("%d", &s[i].roll_number);
printf("Name: ");
scanf(" %[^\n]", s[i].name);
do {
printf("Marks in English (0-100): ");
scanf("%d", &s[i].english);
} while (s[i].english < 0 || s[i].english > 100);
do {
printf("Marks in Computer (0-100): ");
scanf("%d", &s[i].computer);
} while (s[i].computer < 0 || s[i].computer > 100);
do {
printf("Marks in Maths (0-100): ");
scanf("%d", &s[i].maths);
} while (s[i].maths < 0 || s[i].maths > 100);
do {
printf("Marks in Nepali (0-100): ");
scanf("%d", &s[i].nepali);
} while (s[i].nepali < 0 || s[i].nepali > 100);
s[i].total = s[i].english + s[i].computer + s[i].maths + s[i].nepali;
}
printf("\n%-5s %-20s %-8s %-9s %-7s %-8s %-6s\n", "Roll", "Name", "English", "Computer", "Maths", "Nepali", "Total");
printf("----------------------------------------------------------------------------\n");
for (int i = 0; i < STUDENTS; i++) {
printf("%-5d %-20s %-8d %-9d %-7d %-8d %-6d\n",
s[i].roll_number,
s[i].name,
s[i].english,
s[i].computer,
s[i].maths,
s[i].nepali,
s[i].total
);
}
return 0;
}
OR
Write a program in C to create and store name, gender, and phoneno of students to a data file named "ADDRESS.DAT". The program should prompt the user whether to continue or not. The program should also display all the records in the proper format. [8]
Ans:-
#include<stdio.h>
int main()
{
char name[100];
char gender[20];
int phone_no;
char choice='y';
FILE *p;
p=fopen("address.dat","w+");
while(choice!='n')
{
printf("enter name\n");
scanf("%s",&name);
printf("enter gender\n");
scanf("%s",&gender);
printf("enter phone number\n");
scanf("%d",&phone_no);
fprintf(p,"%s\t%s\t%d\n",name,gender,phone_no);
printf("enter y to continue and n to discontinue");
fflush(stdin);
scanf("%c",&choice);
}
rewind(p);
while((fscanf(p,"%s%s%d",name,gender,&phone_no))!=EOF)
{
printf("name =%s\n",name);
printf("gender=%s\n",gender);
printf("phone number=%d\n",phone_no);
printf("-----------------------\n");
}
fclose(p);
return 0;
}
THE END
-----------------------------------------------------------------------------------------------------------
Answer key:
1.) c 2).B 3.) C 4.) D 5.) A 6.) C 7) C 8.)D 9.) D