Operator Operand and Expression in C Operators are symbols which take one or more operands or expressions and perform arithmetic or logical computations. Types of operators available in C are as follows Arithmetic Assignment Logical relational Bitwise These have operators under each as follows Arithmetic Operators...
How does the prefix and postfix operator on expression The operators present in prefix and postfix are prefix increment operator denoted by prefix decrement operator denoted by -- postfix increment operator postfix decrement operator The difference between the two is that in the postfix notation the operator appears...
What is the functionality and restrictions of Modulus Operator When a division is performed the remainder of the operation is given by modulus operator. The modulus operator is denoted in c by symbol . For instance we have two integer values x and y the operation x y called as x modulus y gives the result as x- x y y . If x 18 and...
How to swap two variables without using third variable A variable is a named location in memory that is used to store data which can be modified in a program. Let us learn how to swap two variables without using third variable. This can be done in number of ways By using arithmetic operators By using Bitwise operators By using Pointers...
What is precedence of operators When number of operators occurs in an expression the operator which is to be evaluated first is judged by applying priority of operators. The arithmetic operators available in C are used for Addition - used for Subtraction used for Multiplication used for Division used for Modulus operation When...
How does a conversion occur in C The data types for numerical operations used in C are integer float. It is important to know how conversions occur between these two data types in numerical operations. Some of the facts about conversions are given below Integer having arithmetic operation with Integer gives Integer value Float having...
What is Nonlocal Jump and Unconditional Jump longjmp and setjmp functions implement a nonlocal jump of program execution. longjmp" jumps to a program state previously recorded by setjmp" . Both longjmp and setjmp functions must have the header file given below included. include setjmp.h> When your program...
What is the difference between printf and sprintf sprintf Writes formatted data to a character string in memory instead of stdout Syntax of sprintf is include stdio.h> int sprintf char string const char format item item ... ; Here String refers to the pointer to a buffer in memory where the data is to be written. Format...
Why to avoid goto in C C has goto statement but one must ensure not to use too much of goto statement in their program because its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated. First let us understand the goto statement its syntax and functionality. The goto is a unconditional...
How to assign values during declaration of variables Declaring variables tells the compiler the data type the variable is assigned and no storage area is allocated during this stage. It is possible to assign values during declaration itself. For example consider the following program main int a 50 b 18 5 ; printf a d...
What is sizeof operator sizeof will return the number of bytes reserved for a variable or data type. The sizeof operator is a compile-time operator that returns an integer value. In other words since sizeof is a compile time operator when used in a expression it does not get compiled into executable code in the expression. Syntax of this operator...
How typecasting plays an important role in C C allows programmers to perform typecasting by placing the type name in parentheses and placing this in front of the value. For instance main float a; a float 5 3; gives result as 1.666666 . This is because the integer 5 is converted to floating point value before division and...
The main functions can have arguments passed which are called as command line arguments. There are two command line arguments Argument count denoted by argc and Argument vector denoted by argv The argc is an integer variable which denotes the number of parameters passed and argv is pointer to array of character strings. The syntax is as follows main...
The steps involved in building a C program are 1. First program is created by using any text editor and the file is stored with extension as .c 2. Next the program is compiled. There are many compilers available like GNU C compiler called as gcc Sun compiler Borland compiler which is popular with PC system and so on. Lots of options are available...
There are several format specifiers available in printf. The format specifier used varies depending on the data type used for printing. The given below are some of the format specifiers used with printf in C program. For integer data type the format specifier used with printf is d or i For float data type the format specifier used with printf...
Switch statement is a powerful statement used to handle many alternatives and provides good presentation for C program. But there are some limitations with switch statement which are given below Logical operators cannot be used with switch statement. For instance case k> 20 is not allowed Switch case variables can have only int and char...
What happens when we try to change the value of base address of the string The base address of the sting takes a special place in the context of strings. This is because suing this base address only the string gets identified. In other words the base address therefore takes the position of constant. As we all know it is not possible to change the...
What is the importance of header files The main role of header file is it is used to share information among various files. In brief if we have several functions say 4 functions named as f1 f2 f3 f4 placed in file say sample.c and if all the functions want to get accessed by each other then all must be placed in the same file sample.c. In other...
How does the exit and return differ exit is used to exit the program as a whole. In other words it returns control to the operating system. After exit all memory and temporary storage areas are all flushed out and control goes out of program. In contrast the return statement is used to return from a function and return control to the...
Generally in C program the function definition and calling takes the form as given below main int x y z; z sample x y ; printf d” z ; sample x1 y1 int x1 y1; int z1; z1 x1 - y1; return z1 ; Here what happens is the values x y gets passed to x1 y1 and the value z1 is calculated in sample function...
When a variable is not initialized in main function it contains garbage value. This can be well seen from the example below main int x; printf d” x ; z sample sample printf Testing program” ; Output is x 80 Testing program The above program prints a garbage value...
The default return value from a function is int. In other words unless explicitly specified the default return value by compiler would be integer value from function. When a programmer wants other than integer values to be returned from function then it is essential that the programmer follows the steps provided here below 1....
Headers can be called by using extern C Syntax of extern C is extern C" function declaration> for example to call C functions from C we can write extern C" function declaration> function declaration> ... function declaration> If we want to include a header file sample.h...
The declaration of main can be done as int main One more declaration that can be taken by main is command line arguments form int main int argc char argv or this can also be written as int main argc argv int argc; char argv ; NOTE It is not possible for one to declare the main as void. This is because the function...
Whenever we have more than one function which is called for a finite number of times then such a function gets evaluated from inside out. Let us understand this concept with an example. For instance consider a function sample called within it 4 times as given in program below main int a 50; a sample a sample a sample a sample a ;...
The arguments passed to function can be of two types 1. Values passed 2. Address passed The first type refers to call by value and the second type refers to call by reference. For instance consider program1 main int x 50 y 70; interchange x y ; printf x d y d” x y ; interchange x1 y1 int x1 y1;...
What string function is used to convert a string into long value This is done by using the function named as atol . This function atol is present in the header file named as stdlib.h> . When programmers use this function they must include the header file by the statement include stdlib.h> The syntax...
How to convert a string into an integer in C program This is done by using the function named as atoi . This function atoi is present in the header file named as stdlib.h> . When programmers use this function they must include the header file by the statement include stdlib.h> The syntax for this function is given by int...
What is the string handling functions present in header file string.h> There are number of string handling functions present in string.h. In other words if a programmer uses any of the function present in string.h then they must include the header file as include string.h> Some of the functions present in string.h> are...
How to determine different positions of substrings within a string in C There are numerous functions available in C to achieve the purpose of finding different positions of a substring with a string. strstr To obtain the first occurrence of substring in a string the function used is strstr . The syntax for this function is char strstr const...
What is the return value from printf function printf function always returns the number of characters printed. Let us understand this with an example main int a 10; printf d" printf d d d" a a a ; In this above program the inner printf is first called which prints value of a three times with space...
Ads