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

C Programming Language

The document discusses C programming language style guidelines and basic concepts. It recommends using lowercase for keywords and meaningful names. Key concepts covered include data types like int and float, input/output functions like printf and scanf, arithmetic operators, and type conversion through casts. Comments are used to document programs and enhance readability.

Uploaded by

trxxx.axx
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

C Programming Language

The document discusses C programming language style guidelines and basic concepts. It recommends using lowercase for keywords and meaningful names. Key concepts covered include data types like int and float, input/output functions like printf and scanf, arithmetic operators, and type conversion through casts. Comments are used to document programs and enhance readability.

Uploaded by

trxxx.axx
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

C PROGRAMMING LANGUAGE PROGRAM STYLE AND GUIDELINES

 High-level programming language  C Language is case sensitive and file sensitive.


 Dennis Ritchie (1972)  Lowercase for C reserved words & all standard
 AT&T Bell Laboratories library functions.
 Used to write the UNIX operating system.  Meaningful name for user-defined identifier.
 Avoid using long names
Preprocessor Directive is a C program line beginning
 Avoid using names different only in their
with #
uppercase and lowercase letters.
2 Most Common Preprocessor Directive  Do not use two names differ in the absence of
#include - gives program access to a library that underscore.
causes the preprocessor to insert definitions CONSTANT AND VARIABLE DECLARATIONS
#define - data values that never change or Constant is values that do not change
change rarely
Variable is a name associated with a memory cell
Preprocessor modifies a C program prior to its whose value can change.
compilation.
Variable declarations are statements that communicate
Library is a collection of useful functions and symbols to the compiler the names of variables in the program
that may be accessed by a program.
DATA TYPES
Constant macro is a name that is replaced by a
particular constant value. Data type is a set of values and operations that can be
performed on those values.
Comment is text beginning with /* and ending with */
that provides supplementary information.  int – integers
 double – real numbers
FUNCTION main where program execution begins  char – individual character value
main(void)
INTEGER TYPES IN C
2 Parts of Function Body
Type Range in Typical
Declarations - tells the compiler the names of Implementation
memory cells. int num = 0;
short -32,768 .. 32,767
Executable statements - converted to machine
language instructions & executed by the unsigned short 0 .. 65,535
computer. printf(“Hello World”); int / long −2,147,483,648 .. 2,147,483,647
Identifiers are names that are used in referenced unsigned / unsigned 0 .. 4,294,967,295
variables and various user-defined objects. long
Reserved Words are identifiers from standard a library
that has special meaning on C and cannot be used for
other purposes. • Double C scientific notation, we write this number as
1.23e5 or 1.23E5. Read the letter e or E as “times 10 to
 int the power”
 long
 return FLOATING-POINT TYPES IN C
 short Type Approximate Range
 etc.
float 10−37.. 1038
Standard identifier is a word having special meaning
but one that a programmer may redefine. double 10−307 .. 10308

 printf long double 10−4931 .. 104932


 scanf
User-defined identifiers it is the name the user given to ASSIGNMENT STATEMENT
store data. int sum;
Assignment statement stores a value or a
Rules on Creating User-Defined Identifier computational result in a variable
1. Consist only of letters, digits, and underscores.  C the symbol = is the assignment operator
2. Cannot begin with a digit.  In C it represents an action to be carried out by the
3. C reserved word cannot be used as an identifier. computer
4. C standard library should not be redefined.
UPPERCASE AND LOWERCASE LETTERS
 C compiler considers such usage significant.
INPUT/OUTPUT OPERATIONS AND FUNCTIONS
 The names Rate, rate, RATE are viewed as different
identifiers.
Input Operation is an instruction that copies data from PLACEHOLDERS FOR SPECIFYING NUMERIC
an input device REPRESENTATIONS
Output Operation an instruction that displays PLACEHOLDER MEANING
information stored
%x Hexadecimal (base 16)
Input/output function is a C function that performs an
%o Octal (base 8)
input or output operation. #include<stdio.h>
Function call is calling or activating a function. %d Decimal (signed base 10)

2 Parts of Function Call %u Unsigned Decimal


(unsigned base 10)
 Function name
 Function arguments %e Float or Double in Scientific
Notation

printf FUNCTION return STATEMENT


 Format String - string of characters enclosed in  Transfers control from a function back to the
quotes activator of the function.
 Print List - variables or expressions whose values
are displayed USING COMMENTS
Program documentation is information (comments)
Placeholder is a symbol beginning with % Indicates that enhances the readability of a program.
where to display the output value
OPERATORS IN C
Operator is a symbol, which represents an operation to
be performed.
Arithmetic Expressions help solve most of
programming problems. Allows you to manipulate type
Non-Printing Characters are also called escape int and double data.
sequence or escape characters because of the backslash Arithmetic Operators the operators used in arithmetic
symbol \ expression. Rules for writing and evaluating
expressions.
Newline Escape Sequence is the character sequence \n.
Used to terminate an output line.
ARITHMETIC EXPRESSIONS
Prompt (prompting message) message displayed to
indicate what data to enter and in what form
NON-PRINTING CHARACTERS
ESCAPE SEQUENCE MEANING
\n Newline
\t Horizontal Tab
\\ Backslash
\” Double Quote
TYPE CONVERSION THROUGH CASTS
Type cast converting an expression to a different type
scanf FUNCTION by writing the desired type. n = (int)(9 * 0.5);

 Copies the data from the standard input device. EXPRESSIONS WITH MULTIPLE OPERATORS
 & is the C address-of operator. It tells where to find Unary operator is an operator with one operand. x = -y;
each variable. Binary operators require two operands. x = y + z;
Multiple operators require three or more operator.
PLACEHOLDERS IN FORMAT STRINGS x = a + b – c;
PLACEHOLDER MEANING FUNCTION USE
PRECEDENCE OF ARITHMETIC OPERATORS
%c character printf/scanf
%d or %i integer printf/scanf
%f double printf
%lf double scanf
%s string printf
CONDITIONAL CONSTRUCTS

Control structure is a combination of individual


instructions into a single logical unit with one entry
point and one exit point.

RELATIONAL AND EQUALITY OPERATORS

Logical expression is an expression that uses one or


more of the logical operators

LOGICAL OPERATORS

if CONDITION
 If statement is an example of a control structure.
 If condition selects the statement following the
condition, if the condition is true it allows to execute

NESTED IF STATEMENT
 If statement with another if statement as its true
task or its false task.

MULTIPLE-ALTERNATIVE DECISIONS
 If the statement is obeyed the program continues
with the next instruction following the if statement,
if not the statement is ignored and program
continues with the next.

You might also like