Computer Programming
Computer Programming
Computer Programming
Introduction
• Computer programming is the act of writing computer programs, which are a
sequence of instructions written using a Computer Programming Language to
perform a specified task by the computer.
• There are hundreds of programming languages, which can be used to write
computer programs and following are a few of them −
❑ Java
❑C
❑ C++
❑ Python
❑ PHP
❑ Perl
❑ Ruby
Introduction
• C programming is a general-purpose, procedural, imperative
computer programming language developed in 1972 by Dennis Ritchie
at the Bell Telephone Laboratories to develop the UNIX operating
system.
• C is the most widely used computer language.
• It keeps fluctuating at number one scale of popularity along with Java
programming language, which is also equally popular and most widely
used among modern software programmers.
Why to Learn C Programming?
• char string[20] = {‘g’, ’o’, ‘i’, ‘n’, ‘g’, ‘f’, ‘o’, ‘r’, ‘b’, ’r’, ‘e’, ‘a’, ‘k’, ‘\0’};
• char string[20] = “goingforbreak”;
• char string [] = “goingforbreak”;
• when we declare char as “string[20]”, 20 bytes of memory space is allocated for holding
the string value.
• When we declare char as “string[]”, memory space will be allocated as per the
requirement during the execution of the program.
Special Symbols
The following special symbols are used in C having some special meaning and thus, cannot be used for
some other purpose.[] () {}, ; * = #
❑ Brackets[]: Opening and closing brackets are used as array element reference. These indicate single and
multidimensional subscripts.
❑ Parentheses(): These special symbols are used to indicate function calls and function parameters.
❑ Braces{}: These opening and ending curly braces mark the start and end of a block of code containing
more than one executable statement.
❑ Comma (, ): It is used to separate more than one statements like for separating parameters in function
calls.
❑ Colon(:): It is an operator that essentially invokes something called an initialization list.
❑ Semicolon(;): It is known as a statement terminator. It indicates the end of one logical entity. That’s why
each individual statement must be ended with a semicolon.
❑ Asterisk (*): It is used to create a pointer variable and for the multiplication of variables.
❑ Assignment operator(=): It is used to assign values and for the logical operation validation.
❑ Pre-processor (#): The preprocessor is a macro processor that is used automatically by the compiler to
transform your program before actual compilation.
Operators
• Operators are symbols that trigger an action when applied to C variables and
other objects
• The data items on which operators act upon are called operands.
• Depending on the number of operands that an operator can act upon, operators
can be classified as follows:
• Unary Operators: Those operators that require only a single operand to act
upon are known as unary operators. For Example increment and decrement
operators
• Binary Operators: Those operators that require two operands to act upon are
called binary operators. Binary operators are classified into :
• Arithmetic operators
• Relational Operators
• Logical Operators
• Assignment Operators
• Bitwise Operator
• Ternary Operator: The operator that require three operands to act upon are
called ternary operator. Conditional Operator(?) is also called ternary operator.
Syntax: (Expression1)? expression2: expression3;
Identifiers
• Identifiers are used for the naming of variables, functions, and arrays.
• It is a string of alphanumeric characters that begins with an alphabet, or an
underscore( _ ) that are used for variables, functions, arrays, structures, unions,
and so on.
• It is also known as the user-defined word.
• Identifier names must differ in spelling and case from any keywords. We cannot
use keywords as identifiers; they are reserved for special use. Once an identifier is
declared, we can use the identifier anywhere in the program to refer to the
associated value.
• In programming languages, identifiers are used for identification purposes. Or in
other words, identifiers are the user-defined name of the program components. In
C, an identifier can be a class name, method name, variable name, or label.
Example
int sum()
{
int a,b,s=0;
s=a+b;
printf(“sum is %d”, s);
return(s);
}
No. of identifiers= 4