Programming in C Variables Data Types Input Output 073314

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Programming In C : Variables,

Data Types, Input & Output


Programming is the process of creating a set of instructions that tell a computer how to
perform a task. Programming can be done using a variety of computer programming
languages, such as JavaScript, Python, and C++.
It is hands-on technical skill that involves designing, creating, and refining code to solve
problems, build applications, and more.

• C Language

C is a general-purpose computer programming language. It is very widely used as


machine-independent programming language that is mainly used to create many types of
applications and operating systems such as Windows, and other complicated programs
such as the Oracle database, Git, Python interpreter, and games and is considered a
programming foundation.
(For example, Linux kernel is written in C)

[ C++ is an enhanced version of C programming with object-oriented programming support.]

• VARIABLES

Name of a memory location which stores some data is called Variables.

For example:

Hello.c>
1. #include<stdio.h>

2. // this code displays how data types work in C

3. int main ( ) { (bracket opens)

4.

5. int number = 25 ; (int shows variable is integer; number shows variable and 25 is
a data)

6. char star = ‘’*” ; (here variable is a star)

Programming In C : Variables, Data Types, Input & Output 1


7. int _age = 22; (here variable is an integer)

8. float pi = 3.14; (float used for decimal values)

9. return 0

10. } (bracket closes)

Here;

#include<studio.h> is a preprocessor directive.

( ) is parenthesis

{ is curly braise
int is used data type for integer values.

float is data type for decimal values

• RULES OF VARIABLES

1. Variables are case sensitive.

2. First character is alphabet or ‘’_”.

3. No comma or blank space.

4. No other symbol other than “_”.

• CONSTANTS

A constant is a value or variable that can't be changed in the program, for example: 10,
20, 'a', 3.4, "c programming" etc.

(This picture below shows difference between Constants and Variables)

Programming In C : Variables, Data Types, Input & Output 2


• TYPES OF CONSTANTS
There are three types of constants:

1. Integer Constants (1,2,3,0,-1,-2)

2. Real Constants (1.0, 2.0, 3.14, -2.4)

3. Character Constants (’’a”, “b”, “A”, “#”, “&”, ‘’*”, “@”)

• KEYWORDS

1. Reserved words that have special meaning to compiler are called keywords

2. There are 32 keyboards in C.

3. Certain words reserved cannot be used as variable; these words are keywords.

• COMMENTS

Lines that are not part of program and can be used to explain code, and to make it more
readable are called comments in C. It can also be used to prevent execution when testing
alternative code.

(Comments can be singled-lined or multi-lined).

• OUTPUT & INPUT

Output means to supersede some data on screen printer or any while file. A function is
specific type of relation in which each input value has one and only one output value. An

Programming In C : Variables, Data Types, Input & Output 3


input is the independent value and and output is the dependent value as it depends on the
value of the input.

1. “printf” is the name of one of the main see output functions and stands for print
formatted.

2. There format strings are complementary to scanf format strings which provide
formatted input.

3. printf and scanf are built library functions in C language that perform formatted Input
and formatted output functions.

4. scanf reads data from the standard input stream STD in to the locations given by each
entry in argument list. Each argument list must have a pointer to a variable with a
type that the response to a types specifier in format string.

SOME CASES OF OUTPUT

1. Integers

a. printf("age is %d” , age);

2. Real Numbers

a. printf("value of pi is %f",pi);

3. Characters

a. printf("star looks like this %c", star);

CASES OF INPUT

1. scanf(”%d”,&age);

a. Here %d defines integer

b. & this is amperscent sign

c. Here age us a variable

d. %d is a format specifier

e. Age is put inside a box where age = 25

For example:

Programming In C : Variables, Data Types, Input & Output 4


Hello.c>

1. #include <stdio.h>

2.

3. int main ( ) {

4. int age;

5. printf("enter age”);

6. scanf(”&d",&age);

7. printf("age is : %d", age);

8. return 0

9. }

(when we run the terminal….)

enter age 22
age is : 22

RECAP POINTS:

1. A line containing only white space possibly with a comment is known as blank line and
a C compiler totally ignores it.

2. There are data types in C that refer to an extensive system used for declaring variables
are functions of different types and day determine how much space it occupies in storage
and how the bit pattern is stored is integrated.

3. There are C-types:

a. Basic types

i. Integer types

ii. Floating point types

b. Enumerated types

i. There are again arithmetic types and they are used to define variables that can
only assign certain discrete integer values throughout the program.

c. Type void

Programming In C : Variables, Data Types, Input & Output 5


i. The type specifier void indicates that no value is available.

d. Derived types

i. Pointer types

ii. Array types

iii. Structure types

iv. Union types

v. Function types

4. The array types and structure types are referred collectively as the aggregate types.

5. Variable is nothing but a name given to a Storage area that our programs can manipulate.
Each variable in C has a specific type which determines the size and layout of the
variables memory and the ranges of the values that can be stored within the memory and
also the set of operations that can be performed or applied to the variable.

6. char

a. Typically a single octate or one byte and is an integer type.

7. int

a. Most natural size of integer for machine

8. float

a. A single precision floating point value

9. double

a. Double precision floating point values

10. void

a. Represents the absence of type

11. Variables tell the compiler where and how much storage to create for the variable and the

Programming In C : Variables, Data Types, Input & Output 6

You might also like