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...
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...
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...
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...
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....
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 ;...
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 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...
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;...
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...
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 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...
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...
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...
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...
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 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...