C Programming 1st Chapter
C Programming 1st Chapter
C Programming 1st Chapter
Introduction to C Chapter
Basic I/O 1
1. What is program?
A program is a set of instructions used to control the behavior of a machine, often
a computer.
2. What is programming language?
Salient Features of C language: C has become more popular because of the following
features.
• It is easy to learn.
• It is a structured language.
• It produces efficient program.
• It can handle low level activities.
• It can be compiled on a variety of computer platforms that means it is
platform independent.
4. What is C language.
5. Where, C is used?
C is the most widely used programming language in the world for its high-power
productivity. It is used in different field of computer such as.
7. What is function? How many types of function. Define and give exmaple.
A function is a well-defined program segment that performs some specific tasks.
There are two types of function in C.
Library function/Built-in function:The functions whose name and syntax are predefined
that can not be changed by the programmer are called Built-in function. They are also
called library functions because the definition of these functions are stored in the header
files of C library.
Example: printf(), scanf() etc are library fucntions.
User-defined function:
The function that is defined by the user is called user defined function. Using defferent
library functions, a programmer makes user defined function. Ex- main() function is an
user defined function.
C programming Easy Learning
8. Describe the purpose of #define and #include directives. Why shouldn’t these
directives end with semicolon?
#define directive:
#include directive:
characters. The characters may represent numeric constant, a character constant or a string
constant. Thus, a symbolic constant allows a name to appear in place of a numeric constant, a
#define PASS_MARK 50
#define Pl 3.14159
Symbolic constants are sometimes called constant identifiers. Since the symbolic names are
constants they do not appear in declarations. The following rules apply to the #define statement
which defines a symbolic constant.
1. Symbolic names have the same form as variable names. (Symbolic names are written
in CAPITALS to visually distinguish them from the normal variable names which are
written in lowercase letters. This is only a convention, not a rule.)
2. No blank space between the pound sign and the word define is permitted.
3. #define student must not end with a semicolon.
4. A blank space is required between ^define and symbolic name and between the
symbolic name and constant
5. Symbolic names are not declared for data types.
For example, symbolic constants are more readily identified than the information that they
represent, and the symbolic names usually suggest the significance of their associated data
items.
Const: When any variable has qualified with const keyword in declaration statement then it is
not possible to assign any value or modify it by the program. But indirectly with the help of
pointer its value can be changed.
When any variable is not qualified by const variable then its default qualifier is not const.
There is not any keyword for not const. Its meaning is that value of variable can be changed
after the declaration statement by the program. Example:
#include<stdio.h>
int main()
{
const int a=5;
a++;
printf(“%d”,a);
return 0;
}
Output:
Compiler error, we cannot modify const variable.
Volatile: When any variable has qualified by volatile keyword in declaration statement then
value of variable can be changed by any external device or hardware interrupt. If any variable
has not qualified by volatile keyword in declaration statement, then compiler will take not
volatile as default quantifier. There is not any special keyword for not volatile. Not volatile
means when any variable has qualified by volatile keyword in declaration statement then
value of variable cannot be changed by any external device or hardware interrupt.
C programming Easy Learning
name (byte)
1 -27 to 27-1
Character char %c
unsigned char 1 0 to 27
Unsigned Character
%c
-215 to 215-1
-231 to
1.7e – 308 to
1.7e+308
Float float 4 %f
3.4e – 4932 to
1.1e+4932
Double (long float) double 8 %lf
3.4e – 4932
#include<stdio.h>
int main()
{
int value;
}
Here value is a local variable of main() function.
Global Variable: The variable which is declared outside of all functions and all functions can
access that variable is called Global variable.
Exaple:
#include<stdio.h>
int mark;
int count()
{
……………….
……………….
}
int main()
{
……………….
………………..
}
Here mark is global variable, in this case, count() and main() both functions can use the variable
mark.
12. Write the convention to write a variable in C.
Convention to write the name of a variable or identifier is given below-
1. First character must be an alphabet or underscore.
2. Must be consist of only letters, digits or underscore.
3. Only first 31 characters are significant.
4. Keyword cannot be used.
5. Must not contain white space.
13. Which of following are invalid variable names and why
I. doubles;
II. Minimum;
III. row total;
C programming Easy Learning
IV. 3rd-row;
V. Name.
Static storage class: When a local variable is declared as static, the compiler allocates a
permanent memory space for that variable and when a global variable is declared as static it
is known only by its own file, so it cannot be accessed by another file.
void addition()
{
static int a;
}
Extern storage class: When a variable is needed to use in a file that is declared later in that
file or another file then extern storage class is used.
void main()
{
extern int a, b;
printf(“%d %d”, a,b);
}
main ()
{
Function definition / Function body
}
user-defined function
}
C programming Easy Learning
printf(“ Sentence”);
#include<stdio.h>
int main()
{
printf(“Hello world ! I am a new programmar”);
return 0;
}
#include<stdio.h> Here,
int main() \n - new line
{ \t- tab
printf(“Hello world \n”); \a- alert bell.
printf(“I am a new programmar”); \v- vertically distance.
return 0;
}
Self Task: Write the above program ( program no.2) using the \t, \v, \a.
C programming Easy Learning
Rule-4. If we want to give the value of a variable as an input (from keyboard) then we have to
write-
scanf(“specifier” , &variable_name);
4. Write a program that initialize the value of a variable and print that value.
5. Write a program that takes two integer number and calculate the addition.
6. Write a program that take the radius of a circle as an input and calculate the area of
the circle.
Algorithm / Procedure Program
8. Write a program that takes three integer numbers and interchange them.
Algorithm / Procedure Program
Step-1: We need three variables for three #include<stdio.h>
integer numbers. So, we will declare three
int main()
variables.
{
Step-2: We want to see a message for entering
the values of the three variables. So, we will int a,b,c, temp;
command the computer to show the message.
printf(“Please Enter numbers”);
Step-3: Then we have to give values for that
three variables from the keyboard. So, we will scanf(“%d %d %d”,&a,&b,&c);
command the computer to take input. temp=a;
Step-4: Now, we will declare another variable a=b;
and assign the value of the first variable to
that temporary variable. By this way b=c;
interchange the values of that three variables. c=temp;
Step-5: Now, we will print the values of all printf(“%d %d %d”,a,b,c);
variables respectively.
return 0;
}
C programming Easy Learning
Step-3: Then we have to give value for Celsius printf(“Please Enter the temperature in Celsius
from the keyboard. So, we will command the Scale”) ;
computer to take input. scanf(“%d” , &C);
C programming Easy Learning
pow(a,b)=ab
abs(-a) = a [Finds absolute value of integer]
cos(ϴ)→Finds the cosine value.
sin(ϴ)→Finds the sine value.
tan(ϴ)→Finds the tangent value.
sqrt(a)→√a.
toascii(a)→Finds ASCII value.
tolower(a)→Finds lower case.
toupper(a)-Finds Upper case.