Skip to main content

Posts

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

Header files in C

header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.    There are two types of header files: the files that the programmer writes and the files that comes with your compiler.   You request to use a header file in your program by including it with the C preprocessing directive #include , like you have seen inclusion of stdio.h header file, which comes along with your compiler.   Including a header file is equal to copying the content of the header file but we do not do it because it will be error-prone and it is not a good idea to copy the content of a header file in the source files, especially if we have multiple source files in a program. A simple practice in C  is that we keep all the constants, macros, system wide global variables, and function prototypes in the header files and include that header file wherever it is required. Include Syntax Both the user and the system header