Six Weeks Summer Training On C Programming
Six Weeks Summer Training On C Programming
1. Introduction
High-level languages, for the most part, try to make we as unaware of the hardware
as possible. Clearly, this isn't entirely true, because efficiency is still a major
consideration for some programming languages.
C was initially used for system development work, in particular the programs that
make-up the operating system. Why use C? Mainly because it produces code that runs
nearly as fast as code written in assembly language. Some examples of the use of C
might be:
1. Operating Systems
2. Language Compilers
3. Assemblers
4. Text Editors
5. Print Spoolers
6. Network Drivers
7. Modern Programs
8. Data Bases
9. Language Interpreters
10. Utilities
2. Objectives
1. Basic Concept
2. Variable and Datatype
3. Operators
4. Control Flow
5. Array
6. Function
7. Character String
8. Debugging
9. Pointer
10. Structure
11. File I/O
So, let see some of overview of above Contents.
1. Basic Concept
Structure of C Programme :
Documentation Consist of comment and description
Link Instruction to the compiler to link function from the library function.
Definition Consists of symbolic constants
Global Consists of function declaration and global variables.
Declaration
main( ) Method Every C program must have a main() function which is the starting
point of the program execution.
Subprograms User defined functions
Variable:
In C language, when we want to use some data value in our program, we can store it
in a memory space and name the memory space so that it becomes easier to access it.
Variable is the name of memory location. Unlike constant, variables are changeable,
we can change value of a variable during execution of a program. A programmer can
choose a meaningful variable name.
Datatype:
A variable in C language must be given a type, which defines what type of data the
variable will hold.
Operators:
The symbols which are used to perform logical and mathematical operations in a C
program are called C operators. C language offers many types of operators.
V
3. Control Flow:
1.1 IF:
The if statement is a powerful decision making statement which can handle a single
condition or group of statements
1.2 IF - Else
This statement also has a single condition with two different blocks. One is true block
and other is false block
1.3 IF -Else if ***- Else: When an if statement occurs within another if statement,
then such type of is called nested if statement.
Looping:
1. For Loop:
For loop is similar to while, it's just written differently. for statements are often used
to proccess lists such a range of numbers
2. While loop
while ( expression )
{
Single statement
or
Block of statements;
}
3. Do while
do ... while is just like a while loop except that the test condition is checked at the end
of the loop rather than the start. This has the effect that the content of the loop are
always executed at least once.
Jumping
1. Break Statement:
A break causes the switch or loop statements to terminate the moment it is executed.
Loop or switch ends abruptly when break is encountered.
break;
s[n+1] = '\0';
return n;
2. Continue statements: A continue doesn't terminate the loop, it causes the loop to go
to the next iteration
for( i = 0; i <= j; i ++ )
{
if( i == 5 )
{
continue;
}
printf("Hello %d\n", i );
}
4. Array
Arrays are special variables which can hold more than one value under the same
variable name, organised with an index. Arrays are defined using a very
straightforward. /* defines an array of 10 integers */ int numbers[10];
VIII
5. Function
Types of Functions:
1. Predefined standard library functions : Such as puts(), gets(), printf(), scanf() etc
– These are the functions which already have a definition in header files (.h files like
stdio.h), so we just call them whenever there is a need to use them.
Syntax of function:
Calling function:
6. Character String
C Strings are nothing but array of characters ended with null character (‘\0’). This null
character indicates the end of the string.Strings are always enclosed by double quotes.
Whereas, character is enclosed by single quotes in C.
7. Debugging
On the process of compiling the programme, we have check the following step.
8. Pointer
In C, there is a special variable that stores just the address of another variable. It is
called Pointer variable or, simply, a pointer.
Declaration of Pointer:
data_type* pointer_variable_name;
int* p;
Example:
#include <stdio.h>
int main()
{
int *ptr, q;
q = 50;
/* address of q is assigned to ptr */
ptr = &q;
/* display q's value using ptr variable */
printf("%d", *ptr);
return 0;
}
XI
9. Structure in C
Structure in c language is a user defined datatype that allows us to hold different type
of elements. Each element of a structure is called a member.
It works like a template in C++ and class in Java. we can have different type of
elements in it.
Syntax:
struct struct_name {
DataType member1_name;
DataType member2_name;
DataType member3_name;
…} var_name
Example:
struct StudentData{
char *stu_name;
int stu_id;
int stu_age;};int main(){
/* student is the variable of structure StudentData*/
struct StudentData student;
A file represents a sequence of bytes on the disk where a group of related data is stored. File
is created for permanent storage of data. It is a ready made structure.
Types of Files:
XII
When dealing with files, there are two types of files we should know about:
Text files
Binary files
Text File: Text files are the normal .txt files that we can easily create using Notepad
or any simple text editors.
Binary files : Binary files are mostly the .bin files in our computer.
Function description
I tried many languages like Python, Java ,PHP but finally I came to C, the most
beautiful and charming language of all. I was literally fall in away of simplicity and
elegance of C.
Following are my some of the reason and facts that proposed me to choose C
Programming:
So according to me , think I have given all reason I know why c should be our first
programming language. One thing is for sure that there no other language which more
reliable, simple and easy to use.
XIV
4. Learning Outcomes
• Ability to define and manage data structures based on problem subject domain.
Data structure is a data organization and storage format that enables efficient
access and modification.
Making a solution based on problem domain using C is efficient.
The major advantage of usinbg textual information is all the data is presented
in the form of texts.
Compile-time allocation and determination of size.
Simplest possible storage, conserves space.
Each element has multiple properties associated with it. The multiple
properties always exist one per data element and always exist for every data
element. It seemed like the best organization was an array of objects, to handling
that such type of organization C will be useful.
XV
Using objects in a functional style makes app clean and testable, but it takes
a few carefully considered design patterns, and they’re probably not the ones that
we use.
Defensive programming assumes that 'Murphy's Law' is true, and that "the
worst possible thing will happen, at the worst possible moment," and thus caters
for all possible eventualities.
The degree to which defensive programming is required will be directly
proportional to the required integrity of the program, which will usually depend
on the impact of program failure.
Following are some cases when defensive programming is use for handling
error in execution.
Defend against hardware-level errors
Defend the user against himself.
Defend against program errors.
XVI
5. Gantt Chart
6. Bibliography