You are on page 1of 17

I

1. Introduction

When we learn to program in a high-level language like C (although C is fairly low


level, as high-level languages go), the idea is to avoid worrying too much about the
hardware. we want the ability to represent mathematical abstractions, such as sets,
etc. and have high level language features like threads, higher-order functions,
exceptions.

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 is a procedural programming language. It was initially developed by Dennis


Ritchie between 1969 and 1973. In particular, was created to make it easier to write
operating systems. Rather than write UNIX in assembly, which is slow process
(because assembly code is tedious to write), and not very portable (because
assembly is specific to an ISA), the goal was to have a language that provided good
control-flow, some abstractions (structures, function calls), and could be efficiently
compiled and run quickly.

Many later languages have borrowed syntax/features directly or indirectly from C


language. Like syntax of Java, PHP, JavaScript and many other languages is mainly
based on C language. C++ is nearly a super set of C language (There are few
programs that may compile in C, but not in C++).
II

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

In recent years C has been used as a general-purpose language because of its


popularity with programmers. It is not the world's easiest language to learn and we
will certainly benefit if we are not learning C as we first programming language! C is
trendy (I nearly said sexy) - many well established programmers are switching to C
for all sorts of reasons, but mainly because of the portability that writing standard C
programs can offer.
III

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

 Comments: A "comment" is a sequence of characters beginning with a forward


slash/asterisk combination (/*) that is treated as a single white-space character by
the compiler and is otherwise ignored.

 Preprocessor Directives: C Preprocessor is just a text substitution tool and it


instructs the compiler to do required pre-processing before the actual compilation
Eg. #define MAX 150 ,#include<stdio.h>
IV

 Reading Input and Dislaying Output: C programming has several in-built


library functions to perform input and output tasks.
The scanf() function reads formatted input from standard input (keyboard) .
The printf() function display formatted ouput to the screen.

2. Variable and Datatype

 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.

Example : average, height, age, total etc.

 Datatype:
A variable in C language must be given a type, which defines what type of data the
variable will hold.

 char: Can hold/store a character in it.


 int: Used to hold an integer.
 float: Used to hold a float value.
 double: Used to hold a double val
 Enum :Enumeration (or enum) is a user defined data type in C.

 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:

C Provide three types of control flow. 1. Branching 2. Looping 3.Jumping

1. Branching: It Consist three statements

1.1 IF:

The if statement is a powerful decision making statement which can handle a single
condition or group of statements

Eg: if(n>0) { printf("It is If Statement"); }

1.2 IF - Else

This statement also has a single condition with two different blocks. One is true block
and other is false block

Eg: if(n%2==0){ printf("This is Even Number");}

else { printf("This is Odd Number"); }

1.3 IF -Else if ***- Else: When an if statement occurs within another if statement,
then such type of is called nested if statement.

Eg: if(ram < sham)


VI

if(ram < sham) { if(ram < ajay) { printf("Ram is Youngest"); }

Else { printf("Ajay is Youngest");} }

 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

for( expression1; expression2; expression3)


{
Single statement
or
Block of statements;
}

2. While loop

A while statement is like a repeating if statement. Like an If statement, if the test


condition is true: the statments get execute

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.

do{ single statement or Block of statements; }


while(expression);
VII

 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.

for (n = strlen(s)-1; n >= 0; n--)

if (s[n] != ' ' && s[n] != '\t' && s[n] != '\n')

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

A function is a block of statements that performs a specific task. Suppose we are


building an application in C language and in one of our program, we need to perform
a same task more than once.

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.

2. User Defined functions : he functions that we create in a program are known as


user defined functions.

Syntax of function:

return_type function_name (argument list)


{
Set of statements – Block of code
}

Calling function:

function_name (argument list);

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.

Syntax : char string[20] = “sohaipathan”;

Eg: int main (){ char string[20] = "fresh2refresh.com"; printf( string ); }


IX

Following are some of string function :

strncat ( ) Appends a portion of string to another

strcpy ( ) Copies str2 into str1

strncpy ( ) Copies given number of characters of one string to another

strlen ( ) Gives the length of str1

strcmp ( ) Returns 0 if str1 is same as str2. Returns <0 if strl <


str2. Returns >0 if str1 > str2

strcmpi ( ) Same as strcmp() function. But, this function negotiates


case. “A” and “a” are treated as same.

strchr ( ) Returns pointer to first occurrence of char in str1

strrchr ( ) last occurrence of given character in a string is found

strstr ( ) Returns pointer to first occurrence of str2 in str1

strrstr ( ) Returns pointer to last occurrence of str2 in str1

strdup ( ) Duplicates the string

strlwr ( ) Converts string to lowercase

strupr ( ) Converts string to uppercase

strrev ( ) Reverses the given string

strset ( ) Sets all character in a string to given character

strnset ( ) It sets the portion of characters in a string to given


character

strtok ( ) Tokenizing given string using delimiter


X

7. Debugging

Debugging, in computer programming, is a multistep process that involves identifying


a problem, isolating the source of the problem, and then either correcting the problem
or determining a way to work around it. The final step of debugging is to test the
correction or workaround and make sure it works.

On the process of compiling the programme, we have check the following step.

 Know what our program is supposed to do.


 Detect when it doesn't.
 Fix it.

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;

/*Assigning the values of each struct member here*/


student.stu_name = "Steve";
student.stu_id = 1234;
student.stu_age = 30;

/* Displaying the values of struct members */


printf("Student Name is: %s", student.stu_name);
printf("\nStudent Id is: %d", student.stu_id);
printf("\nStudent Age is: %d", student.stu_age);
return 0;}

10. File Input/Output in C

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.

Following are the operations on the file that we can performed.

1. Creating a new file


2. Opening an existing file
3. Closing a file
4. Reading from and writing information to a file

C provides a number of functions that helps to perform basic file operations.


Following are the functions,

Function description

fopen() create a new file or open a existing file

fclose() closes a file

getc() reads a character from a file

putc() writes a character to a file

fscanf() reads a set of data from a file

fprintf() writes a set of data to a file

getw() reads a integer from a file

putw() writes a integer to a file

fseek() set the position to desire point


XIII

3. Reason for choosing C Programming

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:

1. C is simple it is one of the most powerful languages ever created.


2. As per beginner developer suggestions has been superseded by its predecessors
such as C++, Java,
3. I believe nobody can learn C++ or Java directly. To master these languages we
need to have a strong concept of programming and C will help those who eager to
learn new technologies and language.
4. C is a language which begins from scratch and it has foundational concepts on
which today concepts stand on.
5. When ever it comes to performance (speed of execution), C is unbeatable.
6. C is ideally suited for embedded system programming.
7. It gives we direct access to memory of our CPU through pointers. It allows us to
manipulate and play with bit level 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

After course completion i have the following learning outcomes:

• Understanding a functional hierarchical code organization.

 Don't repeat. Identify similarities among pieces of functionality, and use


recursion techniques to avoid repetitive code.
 The first step to code organization is separating pieces of our application/
programme into distinct pieces; sometimes, even just this effort is sufficient to
lend.

• 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.

• Ability to work with textual information, characters and strings.

 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.

• Ability to work with arrays of complex objects.

 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

• Understanding a concept of object thinking within the framework of functional


model.

 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.

• Understanding a concept of modular programming in C.

 Larger C programs can become difficult to understand and impossible to


maintain . Modular programming is one way of managing the complexity.
 C allows Modular programming groups related sets of functions together into
a module

• Understanding a defensive programming concept. Ability to handle possible


errors during program execution.

 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

Gantt Representation of Summer Training in C Programming


XVII

6. Bibliography

1. Dennis M Ritchie (1993), The Development of the C Language


2. C Programming For Beginners - Master the C Language
https://www.udemy.com/c-programming-for-beginners-/
3. C Language Introduction. (2017, December 03). Retrieved from
https://www.geeksforgeeks.org/c-language-set-1-introduction/
4. Learn C Programming. (n.d.). Retrieved from
https://www.programiz.com/c-programming
5. Tutorials Point. (2018, July 21). C Tutorial. Retrieved from
https://www.tutorialspoint.com/cprogramming/

You might also like