


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This document offers a foundational overview of the c programming language, covering essential concepts such as variables, basic data types (int, char, double), arithmetic operators, and input/output operations using printf and scanf. it also delves into preprocessor directives, comments, and program structure, providing a solid base for beginners to understand the fundamentals of c programming. Examples to illustrate key concepts and explains important rules for writing c code.
Typology: Summaries
1 / 4
This page cannot be seen from the preview
Don't miss anything!
C is an imperative procedural language that supports structured programming, lexical variable scope, recursion, and uses a static type system.
The ancestor of C was called B in 1971. The first version of C was created by Kernighan and Ritchie in 1972. The C99 version, introduced in 1999, allows mixed declarations and executables, variable length arrays, and new types supporting Unicode characters, complex numbers, and boolean values.
A preprocessor is a system program that modifies the C program before compilation. A preprocessor directive is an instruction to the preprocessor. A library is a collection of functions, symbols, and values. Two types of preprocessor directives exist: #include, used to include libraries of functions and macro values. #include <stdio.h> includes the standard input/output header, which contains macro definitions, constants, and declarations of functions and types for standard input and output operations.
Comments are lines of code that are ignored by the compiler.
Instructions, also known as statements, are terminated by a semicolon (;). Line changes and tabs are not significant to the C compiler. For example, a=3; b=4; c=5; is equivalent to a = 3; b = 4; c = 5;.
A basic C program structure includes #include <stdio.h>, additional includes, constant macros, the int main (void) function containing declarative and executable statements, and return (0);.
A simple C program includes the stdio.h header, the main function, a printf statement to display output, and a return (0); statement. The return (0); statement returns an integer (0) to the operating system,
indicating successful program completion. It is typically the last statement in a program.
In programming, variables are used to store data. C has three basic types of variables.
int represents a whole number.
All variables must be declared and have names. Examples include int lifespan;, double mass;, and char letter;.
An identifier must not be a reserved word. An identifier must never begin with a digit. An identifier should not be a standard identifier. Examples of valid and invalid identifiers are provided.
Executable statements should come after the declarations in a function for compatibility with all compilers.
An assignment statement copies the value on the right-hand side of the = operator to the variable on the left-hand side. For example: kms = KMS_PER_MILE * miles;. Assignment is not the same as an algebraic equation. For example, sum = sum + item; is a valid assignment. The right side of an assignment can be a constant, a variable, or an expression.
The printf statement displays a line of program output. It uses a print list, which contains the variables or expressions whose values are displayed. Placeholders, symbols beginning with % in a format string, indicate where to display the output value. For example: printf ('That equals %lf kilometers. \n', kms);.
%c is used for char variables in printf and scanf.
The arithmetic operators in C include + (addition), - (subtraction), * (multiplication), / (division), and % (remainder). Integer expressions always return integer results. For example, 5 + 2 is 7 , 5.0 + 2.0 is 7.0, 5 - 2 is 3 , 5.0 - 2.0 is 3.0, 5 * 2 is 10 , 5.0 * 2.0 is 10.0, 5.0 / 2. is 2.5, 5 / 2 is 2 , and 5 % 2 is 1.
An operation with two integer operands always gives an integer answer.
A unary operator is an operator with one operand. For example: x = y + z;.
Rule #1: Parentheses Rule - All sub-expressions are evaluated separately. Rule #2: Operator Precedence Rule - unary + - first, * / % next, binary + - last. Rule #3: Associativity Rule - Right Associativity: Unary operators in the same expression and at the same precedence level are evaluated right to left.
Representational error is an error due to coding a real number as a finite number of binary digits. Arithmetic underflow is an error in which a very small computational result is represented as zero.
Interactive mode involves the user responding to prompts by typing in data.
To read from a file, you need first to declare it (FILE is all uppercase). fclose (in);
To create a new file and write into it from a file, you need first to declare it. fclose (out);
Syntax errors are violations of the C grammar rules.