0% found this document useful (0 votes)
67 views

What Is A Symbolic Constant ?

A symbolic constant is a variable whose value does not change during the program. They are usually defined at the beginning using #define. Some common mathematical constants include Pi (3.1415926535). Symbolic constants allow using meaningful names instead of direct values, making code more readable. Input/output of single characters uses getchar() and putchar(), while strings use gets() and puts(). Formatted I/O uses scanf() and printf() with format specifiers like %d for integers and %f for floats to read and write data.

Uploaded by

Pugal Vendan
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)
67 views

What Is A Symbolic Constant ?

A symbolic constant is a variable whose value does not change during the program. They are usually defined at the beginning using #define. Some common mathematical constants include Pi (3.1415926535). Symbolic constants allow using meaningful names instead of direct values, making code more readable. Input/output of single characters uses getchar() and putchar(), while strings use gets() and puts(). Formatted I/O uses scanf() and printf() with format specifiers like %d for integers and %f for floats to read and write data.

Uploaded by

Pugal Vendan
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/ 11

What is a symbolic constant ?

Asymbolic constantisan"variable"whosevaluedoesnot
changeduringtheentirelifetimeoftheprogram...
Theyareusuallydefinedatthebeginningoftheprogram.
SomeconstantsinMathematics:

Name of the constant Value of the constant


Pi

3.1415926535...

#include<stdio.h>
#include<conio.h>
#defineTRUE1
#definePI3.141593
voidmain()
{
floata;
floatb;
floatc;
floatd=PI;
clrscr();
if(TRUE)
{
a=100;
b=a*10;
c=b-a;
}
printf("\na=%f\nb=%f\nc=%f\nPI=%f",a,b,c,d);
getch();
}

Single Character Input Output


To take input of a single character we can also usegetcharfunction by
writing.
char c = getchar();
It will ask for a character from user and save that value to variable c.
In the same wayputcharfunction print single character as output.
Syntax isputchar(c);
Here c is the character variable name.

String Input and Output


To take input of a multiple characters we can also use gets
function by writing.
gets(c);
It will ask for multiple characters from user and save that value
to variable c.
In the same way puts function print multiple characters as
output. Syntax is
puts(c);
Here c is the string variable name.
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
char a[10];
c=getchar();
gets(a);
puts(a);
putchar(c);
getch();
}

Formatting input and output


scanf function is used for reading formatted input and
printf statement is used for printing the output in a particular
format.

The general syntax of printf and scanf are as follows


scanf(control
string,&arg1,&arg2,&arg3.&argn);
arg1.argn - specify the address of the
locations where the data is stored. It is generally
preceded by an ampersand(&) symbol.
control string - %d (integer)
%f (float)
%c (char)

printf(control string,arg1,arg2,arg3.argn);
Control string specifies the field specifications consisting of
the % symbol, data type, and an optional number specifying the
field width. It also includes blanks, tabs, new lines.
Conversion specifications for scanf
a) The field specification for reading an integer number is
%wd where w stands for the width. This width should be large
enough to obtain the input data size.
b) Input items are separated by spaces or tabs and the
format specifications should match the arguments in order.

c) An input value can be skipped by specifying * in the place of width


Example:
printf(%d %*d %d,&a,&b);
Let the data be as follows
2 8 10
then a=2 and b=10(since 8 is omitted).
d)The specification for
integer
%d
long int
%ld
float
%f or %e
double
%lf
single character
%c.
string
%s.
octal
%o
unsigned int
%u
hexa decimal
%x

e) Any unread data items will be considered to be the


input for the next scanf.
Example:
char a[10],b[10];
..
scanf(%s,a);
scanf(%s,b);

printf(%s %s,b,a);

Then if New York is the input given, the output of the


printf statement will be York New

Conversion specifications for printf:


1. The format specification in the printf statement has
the following form %w.p type specifier where
w is an integer number that specifies the
total number of columns for the output value
p-

specifies the number of digits to the right of the

decimal point (in a real number) or the number of


characters to be printed from a string.
2. For integer numbers width can be specified. The
number is usually right justified. It can be left justified by
preceding the type specifier with a minus sign.

3. It is also possible to fill the leading blanks by zero


using %0d
4. The output of a real number is enabled by the
format %w.p f
where
w total number of positions
p number of digits after the decimal point.
5. Can also display in the exponential form using
%w.p e
6. To print a single character use %c

You might also like