C Language
C Language
3. What is a token?
The individual elements of a program are called Tokens. There are following 6 types of
tokens are available in C:
• Identifiers
• Keywords
• Constants
• Operators
• Special Characters
• Strings
4. What is the use of printf() and scanf() functions? Also explain format
specifiers?
Some datatype format specifiers for both printing and scanning purposes are as follows:
• %d: It's a datatype format specifier for printing and scanning an integer value.
• %s: It's a datatype format specifier for printing and scanning a string.
• %c: It's a datatype format specifier for displaying and scanning a character value.
• %f: The datatype format specifier %f is used to display and scan a float value
Explanation: The string mentioned "abxdef" is an array, and the expression is equal to
"abxdef"[5]. Why is the inside-out expression equivalent? Because a[b] is equivalent to
*(a + b) which is equivalent to *(b + a) which is equivalent to b[a].
The most commonly used built-in functions in C are scanf(), printf(), strcpy, strlwr,
strcmp, strlen, strcat, and many more.
Built-function is also known as library functions that are provided by the system to make
the life of a developer easy by assisting them to do certain commonly used predefined
tasks. For example, if you need to print output or your program into the terminal, we
use printf() in C.
7. What is a Preprocessor?
In C, #line is used as a preprocessor to re-set the line number in the code, which takes
a parameter as line number. Here is an example for the same.
#include <stdio.h>
/*line 1*/
/*line 2*/
int main(){
/*line 3*/
/*line 4*/
printf("Hello world\n"); /*line
5*/
//print current line /*line
6*/
printf("Line: %d\n",__LINE__); /*line 7*/
//reset the line number by 36 /*line 8*/
#line 36 /*reseting*/
//print current line /*line
36*/
printf("Line: %d\n",__LINE__); /*line 37*/
printf("Bye bye!!!\n");
/*line 39*/
/*line 40*/
return 0;
/*line 41*/
}
/*line 42*/
The function takes the string as an input that needs to be converted to an integer.
Return Value:
The function takes a pointer to an array of char elements that need to be converted, and
a format string needs to be written in a buffer as a string
The output after running the above code: Output: Value of Pi = 3.141593
11. What is recursion in C?
When a function in C calls a copy of itself, this is known as recursion. To put it another
way, when a function calls itself, this technique is called Recursion. Also, this function is
known as recursive function.
void do_recursion()
{
... .. ...
do_recursion();
... .. ...]
}
int main()
{
... .. ...
do_recursion();
... .. ...
}
After you compile the C source, the symbol names need to be intact in the object code.
If we introduce function overloading in our source, we should also provide name
mangling as a preventive measure to avoid function name clashes. Also, as C is not a
strictly typed language many things(ex: data types) are convertible to each other in C.
Therefore, the complexity of overload resolution can introduce confusion in a language
such as C.
When you compile a C source, symbol names will remain intact. If you introduce function
overloading, you should provide a name mangling technique to prevent name clashes.
Consequently, like C++, you'll have machine-generated symbol names in the compiled
binary.
Additionally, C does not feature strict typing. Many things are implicitly convertible to
each other in C. The complexity of overload resolution rules could introduce confusion
in such kind of language