0% found this document useful (0 votes)
5 views17 pages

Welcome To Sowmya Tutorials: Bca 1St Semester - Nep - Introduction To C Programming

The document provides an introduction to C programming, covering data types, variables, and their declaration and initialization. It explains the difference between local and global variables, as well as symbolic constants and input/output functions in C. Additionally, it details formatted and unformatted I/O functions, including examples of usage for each type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views17 pages

Welcome To Sowmya Tutorials: Bca 1St Semester - Nep - Introduction To C Programming

The document provides an introduction to C programming, covering data types, variables, and their declaration and initialization. It explains the difference between local and global variables, as well as symbolic constants and input/output functions in C. Additionally, it details formatted and unformatted I/O functions, including examples of usage for each type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

WELCOME TO SOWMYA TUTORIALS

CLASS: BCA 1st SEMESTER | NEP|

INTRODUCTION TO C PROGRAMMING| L4

CHAPTER 1: INTRODUCTION TO C PROGRAMMING


There are 4 types of data types in C language
 The basic data types are integer-based and floating-point based. C language supports
both signed and unsigned literals. The memory size of basic data types may change
according to 32 or 64 bit operating system.
VARIABLES

A variable is a name of memory location. It is used to store data. Variables are changeable, we can change value of
a variable during execution of a program. It can be reused many times.

Note: Variable are nothing but identifiers.

Rules to write variable names:

1. A variable name contains maximum of 30 characters/ Variable name must be upto 8 characters.

2. A variable name includes alphabets and numbers, but it must start with an alphabet.

3. It cannot accept any special characters, blank spaces except under score( _ ).

4. It should not be a reserved word.

Ex : i rank1 MAX min Student_name StudentName class_mark


Declaration of Variables

A variable can be used to store a value of any data type. The declaration of variables must be done
before they are used in the program.

The general format for declaring a variable.

Syntax : data_type variable-1,variable-2,------, variable-n;

Variables are separated by commas and declaration statement ends with a semicolon.

Ex : int x,y,z;

float a,b;

char m,n;
Assigning values to variables / Initialization of Variables

values can be assigned to variables using the assignment operator (=).

The general format statement is :

Syntax : variable = constant;

Ex : x=100;

a= 12.25;

m= ‘ f ’;

we can also assign a value to a variable at the time of the variable is declared.

The general format of declaring and assigning value to a variable is :

Syntax : data_type variable = constant;

Ex ; int x=100;

float a=12.25;

char m= ‘ f ‘ ;
Types of Variables in C

There are many types of variables in c:

1. Local variables: variables are declared within the functions or the main functions are called local variables.

Example: void main( )

int a, b; // Local Variables

int sum( )

int p, q; // Local Variables

……..

……..

}
2. Global variables: variables are declared outside the main functions are called global
variables.

Example: int a, b; // Global Variables

void main( )

…..

……

}
SYMBOLIC CONSTANTS
A symbolic constant is a name given to some numeric constant, or a character constant or string
constant, or any other constants.

Symbolic constant names are also known as constant identifiers. Pre-processor


directive #define is used for defining symbolic constants.

Syntax for Creating Symbolic Constants

#define symbolic_constant_name value_of_the_constant

Symbolic Constants Examples

#define PI 3.141592
#define GOLDENRATIO 1.6
#define MAX 500

Here PI, GOLDENRATIO, SIZE are symbolic constants


INPUT AND OUTPUT WITH C
FORMATTED AND UNFORMATTED CONSOLE I/O FUNCTIONS.

Input: In any programming language input means to feed some data into program. This can be given in the form of file or
from command line.

Output: In any programming language output means to display some data on screen, printer or in any file.

The Standard Files

C programming treats all the devices as files. So devices such as the display are addressed in the same way as files and the
following three files are automatically opened when a program executes to provide access to the keyboard and screen.

Standard File File Pointer Device

Standard input stdin Keyboard

Standard output stdout Screen

Standard error stderr Your screen


Input / Output functions are classified into two types
Formatted I/O Functions

Formatted I/O functions operates on various types of data.

1 : printf() : output data or result of an operation can be displayed from the computer to a standard output device using
the library function printf(). This function is used to print any combination of data.

Syntax : printf(“control string “, variable1, variable2, -----------, variable-n);

Ex : printf(“%d”,3977); // Output: 3977

printf() statement another syntax :

Syntax : printf(“formatting string”);

Formating string : it prints all the character given in double quotes (“ ”) except formatting specifier.

Ex : printf(“ hello “);-> hello

printf(“a”); -> a

printf(“%d”, a); -> a value

printf(“%d”); -> no display


2. scanf() : input data can be entered into the computer using the standard input „C‟ library function
called scanf(). This function is used to enter any combination of input.

Syntax : scanf(“control string “,&var1, &var2,----, &var-n);

The scanf() function is used to read information from the standard input device (keyboard).

Ex : scanf(“ %d “,&a);-> hello

Each variable name (argument) must be preceded by an ampersand (&). The (&) symbol gives the
meaning “address of ” the variable.
Unformatted I/O functions

a) Character I/O b) String I/O

a) character I/O

1. getchar(): Used to read a character from the standard input

2. putchar(): Used to display a character to standard output

3. getch() and getche(): these are used to take the any alpha numeric characters from the standard input getche()
read and display the character getch() only read the single character but not display

4. putch(): Used to display any alpha numeric characters to standard output

b) String I/O:

1. gets(): Used for accepting any string from the standard input(stdin) eg: gets()

2. puts(): Used to display a string or character array Eg:puts()

3. Cgets():read a string from the console eg; cgets(char *st)

4. Cputs():display the string to the console eg; cputs(char *st)


THANK YOU
If you like my videos please do subscribe
and click on the bell icon for the
notification of the new videos.

You might also like