0% found this document useful (0 votes)
17 views

C Programming

Uploaded by

nischaltu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C Programming

Uploaded by

nischaltu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

THE

PROGRAMMING
LANGUAGE
Author of the Document: Recipient of Document:
Nischal Tulachan, Keshab Maharjan,
Student of Grade 9, Oscar. Department of Computer Science

DOCUMENTATION ON C PROGRAMMING LANGUAGE

1
ACKNOWLEDGEMENTS
I would like to express my sincere gratitude to all those who have supported and guided me in
the process of writing this C programming language documentation.

First and foremost, I would like to thank my parents for their unconditional love, unwavering
support, and endless encouragement. They have always been there for me, providing me with
the necessary resources, and motivating me to pursue my passion for programming. Their
patience and guidance have been invaluable in helping me understand the complex concepts
and syntax of C language.

I would also like to express my gratitude to my school teachers who have played a crucial role
in my journey as a programmer. I am indebted to my computer science teacher, who has
always been available to provide me with feedback and guidance in my programming
assignments. Special thanks to my language arts teacher who has taught me the importance of
clear and concise writing, which has helped me present the information in this documentation
in an organized and understandable manner.

I would also like to extend my appreciation to my friends, who have been my constant source
of motivation and inspiration. They have provided me with feedback, suggestions, and
constructive criticism, which have helped me refine my writing skills and improve the overall
quality of this documentation.

I am also grateful to the open-source community, who has generously shared their knowledge
and resources on C programming language. Their contributions have been invaluable in
helping me understand the language and its nuances, which has enabled me to present the
information in this documentation in a comprehensive and meaningful way.

Lastly, I would like to acknowledge the support and encouragement I have received from my
classmates and peers. Their positive feedback and appreciation have motivated me to work
harder and produce a documentation that meets their needs and expectations.

In conclusion, I am truly grateful to everyone who has supported me in this endeavor. Your
guidance, support, and encouragement have been instrumental in making this documentation a
reality. Thank you all for your contribution.

CONTINUING FORWARD…
2
TABLE OF CONTENTS

Topic Contents Page No.


General preface to the origins of C.
From its history to its features, and its Page-4
Introduction to C relevance in the education curriculum in
Nepal and its role in facilitating students’
critical thinking skills.

General preface to the elements of C, such as


its characters-set, keywords, variables,
Elements of C constants, operators and expressions and many Page-5 to 6
more.

Structure of C Program A meticulously-drawn function of each import- Page-7


ant aspect in the C programming language.

A meticulously-drawn function of each Page-8


Keywords in C programming keywords of relevance to a beginner of C
programming language.

Branching Statements in A meticulously-drawn function of each Page-9


branching statements of relevance to a begin-
C Programming ner of the C programming language.

A meticulously-drawn function of each


type of loop of relevance to a beginner of C
Looping Statements in C programming language which ascertains the Page-10
proficiency of the beginner.

Sample Programs of C A list of 16 sample programs of C language. Page-11 to 16

This topic is self-explanatory. Page-17


Conclusion & Citations

CONTINUING FORWARD…

3
INTRODUCTION TO C PROGRAMMING

C is a programming language that has had a profound impact on the world of computing. It was
created to be a system programming language, which means that it is used to create software
that interacts with the hardware of a computer system. C was designed to be portable, efficient,
and low-level, which made it ideal for use in operating systems, embedded systems, and other
applications where performance and reliability are critical.

One of the key advantages of C is its simplicity. The language has a relatively small and
straightforward syntax, which makes it easy to learn and use. However, this simplicity can also
be a disadvantage, as it can lead to errors if not used carefully. C is a compiled language, which
means that source code is compiled into machine code that can be run on a specific hardware
platform. This compilation process makes C programs faster and more efficient than
interpreted languages.

C has also had a significant impact on the development of other programming languages. C++
is a language that was developed from C and adds support for object-oriented programming,
while Java was heavily influenced by C and was designed to be a more portable and secure
language for networked computing. Python is another language that has been influenced by C,
particularly in its use of modules and libraries.

Despite the emergence of newer programming languages, C remains an important language for
system programming and embedded systems. Many operating systems, including Unix, Linux,
and Windows, are written in C, and it is also widely used in embedded systems such as
microcontrollers and digital signal processors. C is also used in scientific computing and other
applications where performance and low-level access to hardware are important.

In conclusion, C is a powerful and influential programming language that has been used for
over four decades. Its simplicity, efficiency, and low-level access to hardware have made it
ideal for system programming and embedded systems, and it has influenced many other
programming languages that have followed it. Despite the emergence of newer languages, C
continues to be a fundamental language for anyone interested in programming.

CONTINUING FORWARD…

4
ELEMENTS Of C PROGRAMMING

C Programming Character-set:

Like any other programming language such as QBASIC, C, too, has its own set of characters
which are its very own C character-set. A character represents any digit, letter, or any types of
signs. C, like QBASIC, possesses the following characters:
i.) Alphabets: A to Z (Small and capital letters.)
ii.) Numbers: 0 to 9.
iii.) Special Characters: ; = , + - * / ^ % $ @ # “ : < > \ | ‘

Variables:

Variables are the storage locations in the computer’s memory for storing data. It is referred to
by a name and whose value can be altered during the execution of the program. The types are:
i.) Numeric variable: A numeric variable has a number as its value.
ii.) String variable: A string variable has a string as its value.

Syntax: data_type variable_name = value; // defining single variable


Or,
data_type variable_name1, variable_name2; // defining multiple variable

Constants:

Constants is a value stored in a program which does not change during execution of the
program. Its types are:
i.) Numeric constant: A numeric constant is a numeric value in which arithmetic operations are
performed.
ii.) String constant: A string constant is a set of alphanumeric or special characters enclosed in
brackets.

Syntax: const <data type> <name_1> = <value_1>;

Operators and Expressions:

An operator is a symbol representing the operations they perform on operands in a program.


Operands are the values on which the operators work. The types of operators are:

5
i.) Arithmetic Operators: Arithmetic operators are used to perform basic arithmetic
operations on numeric operands. The arithmetic operators in C include addition (+),
subtraction (-), multiplication (*), division (/), and modulus (%).

ii.) Relational Operators: Relational operators are used to compare two operands and return a
Boolean value of true or false. The relational operators in C include equal to (==), not equal to
(!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to
(<=).

iii.) Logical Operators: Logical operators are used to perform logical operations on Boolean
operands. The logical operators in C include logical AND (&&), logical OR (||), and logical NOT
(!).

iv.) Bitwise Operators: Bitwise operators are used to perform operations on individual bits of
a number. The bitwise operators in C include bitwise AND (&), bitwise OR (|), bitwise XOR (^),
bitwise NOT (~), left shift (<<), and right shift (>>).

v.) Assignment Operators: Assignment operators are used to assign a value to a variable. The
assignment operators in C include the simple assignment operator (=), compound assignment
operators (+=, -=, *=, /=, %=, &=, |=, ^=, <<=, and >>=).

Keywords:

Keywords in C are reserved words that have specific meanings in the programming language.
These words are part of the C language syntax and cannot be used for any other purpose,
such as variable names or function names. Here is a list of keywords in C programming:
1. auto 9. do 17. Int 25. struct
2. break 10. Else 18. Long 26. switch
3. case 11. Enum 19. Register 27. typedef
4. char 12. Extern 20. Return 28. union
5. const 13. Float 21. Short 29. unsigned
6. continue 14. For 22. Signed 30. void
7. default 15. Goto 23. Sizeof 31. volatile
8. double 16. If 24. Static 32. while

6
STRUCTURE OF C PROGRAM

#include <stdio.h>

Int main() {
printf(“Hello, world!\n”);
return 0;
}

Now, let’s break down each element:


i.) #include <stdio.h>: This line is a preprocessor directive that tells the compiler to include
the standard input/output library, which is necessary for using functions such as printf().

ii.) int main() { }: This is the main function of the program, and it is where the execution of the
program begins. In this example, the function has a return type of int, which means that it will
return an integer value. The function takes no arguments, which is indicated by the empty
parentheses.

iii.) printf("Hello, world!\n"); This line uses the printf() function to output the string "Hello,
world!" to the console. The \n character is used to indicate a newline.

iv.) return 0; This line ends the main() function and returns an integer value of 0 to indicate
successful completion of the program.

In summary, the basic structure of a C program includes a preprocessor directive to include any
necessary libraries, a main() function where the execution of the program begins, and various
statements and functions to perform tasks such as input/output, calculations, and control flow.
By understanding the basic structure of a C program, programmers can begin writing their own
programs and building more complex applications.

CONTINUING FORWARD…

7
KEYWORDS IN C PROGRAMMING
i.) main: The main function is the entry point of a C program and contains the code that is
executed when the program runs.

ii.) while: Used to implement loops that allow a block of code to be executed repeatedly as
long as a certain condition is true.

iii.) for: Used to implement loops that allow a block of code to be executed a fixed number of
times.

iv.) switch: Used to implement a multi-way branch statement that allows the program to
execute different code based on the value of an expression.

v.) break: Used to exit a loop or switch statement prematurely.

vi.) continue: Used to skip the rest of the current iteration of a loop and move on to the next
iteration.

vii.) int: Used to declare variables that hold integer values.

viii.) double: Used to declare variables that hold double-precision floating-point values.

ix.) float: Used to declare variables that hold floating-point values.

x.) char: Used to declare variables that hold character values.

xi.) const: Used to declare variables as constant, i.e., their values cannot be changed after
initialization.

xii.) void: Used to indicate that a function does not return any value.

xiii.) return: Used to return a value from a function and exit the function.

xiv.) sizeof: Used to determine the size of a data type or variable in bytes.

xv.) typedef: Used to create a new name (alias) for an existing data type.

xvi.) struct: Used to define a new composite data type that groups together variables.

8
BRANCHING STATEMENTS
i.) IF Statement:

The if statement allows the program to execute a block of code if a certain condition is true. If
the condition is false, the code inside the if block is skipped.

ii.) IF-ELSE Statement:

The else-if statement allows the program to test multiple conditions in a sequence and execute
the code associated with the first condition that is true.

iii.) SWITCH Statement:

The switch statement allows the


program to execute different blocks
of code depending on the value of
an expression. The case statements
specify the different values to test
for, and the default specifies what
to do if none of the cases match.
Overall, these branching statements
are essential in C programming to
enable conditional execution of code.

9
LOOPING STATEMENTS
i.) WHILE LOOP:

The while loop allows the program to execute a block of code repeatedly while a certain
condition is true. If the condition is false, the loop is skipped entirely.

ii.) DO-WHILE LOOP:

The do-while loop is similar to the while loop, but it guarantees that the code inside the loop
will be executed at least once, even if the condition is initially false.

iii.) FOR LOOP:

The for loop allows the program to execute a block of code repeatedly for a fixed number of
times, with an optional initialization and an update statement.

CONTINUING FORWARD…
10
SAMPLE PROGRAMS IN C LANGUAGE

11
12
13
14
15
16
CONCLUSION AND CITATIONS
In conclusion, documentation is an essential aspect of C programming. It provides a way for
programmers to communicate the purpose, functionality, and usage of their code to other
developers or users. Effective documentation should be clear, concise, and provide enough
information for readers to understand the code and how to use it.

In C programming, documentation can take many forms, including comments in the code,
function prototypes, and documentation files. Comments in the code are especially useful for
explaining how certain sections of code work, while function prototypes provide information on
the input and output parameters of a function. Documentation files, such as README files,
provide an overview of the entire project and its purpose.

Documentation is important not only for other developers but also for the programmer
themselves. Clear documentation can help to reduce bugs and errors by making it easier to
understand the code and its intended purpose. Additionally, documentation makes it easier to
maintain and modify code in the future.

In summary, documentation is a critical aspect of C programming, and programmers should


make an effort to create clear and concise documentation that communicates the purpose,
functionality, and usage of their code. By doing so, programmers can improve the
maintainability, usability, and overall quality of their code.

CITATIONS:
1. Ritchie, Dennis M. (March 1993). "The Development of the C Language". ACM SIGPLAN
Notices. ACM. 28 (3): 201–208. doi:10.1145/155360.155580.
2. Ritchie, Dennis M. (1993). "The Development of the C Language". The Second ACM
SIGPLAN Conference on History of Programming Languages (HOPL-II). ACM. pp. 201–
208. doi:10.1145/154766.155580. ISBN 0-89791-570-4. Retrieved November 4, 2014.
3. Kernighan, Brian W.; Ritchie, Dennis M. (1988). The C Programming
Language (2nd ed.). Prentice Hall. ISBN 0-13-110362-8.
4. Kernighan, Brian W.; Ritchie, Dennis M. (March 1988). The C Programming
Language (2nd ed.). Englewood Cliffs, NJ: Prentice Hall. ISBN 978-0-13-110362-7.
5. C Library Reference and Examples

THE END…

17

You might also like