Skip to main content

Posts

Control Statements in C

Control statements enable us to specify the flow of program control; ie, the order in which the instructions in a program must be executed. They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another. There are four types of control statements in C:  1.Decision making statements 2.Selection statements 3.Iteration statements 4.Jump statements  1.Decision Making Statement: the if-else Statement The if-else statement is used to carry out a logical test and then take one of two possible actions depending on the outcome of the test (ie, whether the outcome is true or false).  Syntax: if (condition) { statements } else { statements }  If the condition specified in the if statement evaluates to true, the statements inside the if-block are executed and then the control gets transferred to the statement immediately after the if-block. Even if the condition is false and no else-block is present, control gets transferred to t

Input Output-printf() and scanf()

printf() and scanf() function in C   printf() and scanf() functions are inbuilt library functions in C programming language which are available in C library by default.These functions are declared and related macros are defined in “stdio.h” which is a header file in C language. We have to include “ stdio.h ” file as shown in below to make use of these printf() and scanf() library functions in C program. #include <stdio.h>   printf() function in C   In C programming language, printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen. Here’s a quick summary of the available printf format specifiers:   %c           character %d           decimal (integer) number (base 10) %ld         Long integer %e           exponential floating-point number %f           floating-point number %lf          double number %i            integer (base 10) %o         octal number (base 8) %s         a string of characters %u     

C Operators , precedence and Expressions

C – Operators and Expressions The symbols which are used to perform logical and mathematical operations in a C program are called C operators. These C operators join individual constants and variables to form expressions. Operators, functions, constants and variables are combined together to form expressions. Consider the expression A + B * 5. where, +, * are operators, A, B are variables, 5 is constant and A + B * 5 is an expression. Types of C operators: C language offers many types of operators. They are, Types of Operators Description Arithmetic operators These are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus Assignmentoperators These are used to assign the values for the variables in C programs. Relational operators These operators are used to compare the value of two variables. Logical operators These operators ar

Data Types and Qualifiers in C

There are four data types in C language. They are, Types Data Types   Basic data types   int, char, float, double   Enumeration data type   enum   Derived data type   pointer, array, structure, union   Void data type   void Here we will discuss only basic data types. Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one:   Following are the examples of some very common primitive data types used in C:   char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. int: As the name suggests, an int variable is used to store an integer. float: It is used to store decimal numbers (numbers with floating point value) with single precision. double: It is used to store decimal numbers (numbers with floating point value) with double pr