0% found this document useful (0 votes)
39 views

C Language

C is called a mid-level language because it has characteristics of both low-level assembly and higher-level languages. It allows developing operating systems as well as applications. Some key features of C include being simple and efficient, portable, structured, and having a rich function library for dynamic memory management. A token is an individual element of a C program, such as identifiers, keywords, constants, operators, special characters, and strings. Common built-in functions include printf() and scanf() for input/output with format specifiers, and strcpy() for strings.

Uploaded by

Akhilesh Misra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

C Language

C is called a mid-level language because it has characteristics of both low-level assembly and higher-level languages. It allows developing operating systems as well as applications. Some key features of C include being simple and efficient, portable, structured, and having a rich function library for dynamic memory management. A token is an individual element of a C program, such as identifiers, keywords, constants, operators, special characters, and strings. Common built-in functions include printf() and scanf() for input/output with format specifiers, and strcpy() for strings.

Uploaded by

Akhilesh Misra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Why is C called a mid-level programming language?

C has characteristics of both assembly-level i.e. low-level and higher-level languages. So


as a result, C is commonly called a middle-level language. Using C, a user can write an
operating system as well as create a menu-driven consumer billing system.

2. What are the features of the C language?

Some features of the C language are-

1. It is Simple And Efficient.


2. C language is portable or Machine Independent.
3. C is a mid-level Programming Language.
4. It is a structured Programming Language.
5. It has a function-rich library.
6. Dynamic Memory Management.
7. C is super fast.
8. We can use pointers in C.
9. It is extensible.

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?

• printf() is used to print the output on the display.


• scanf() is used to read formatted data from the keyboard.

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

5. What's the value of the expression 5["abxdef"]?

The answer is 'f'.

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

6. What is a built-in function in C?

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?

A preprocessor is a software program that processes a source file before sending it to


be compiled. Inclusion of header files, macro expansions, conditional compilation, and
line control are all possible with the preprocessor.
8. In C, What is the #line used for?

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*/

9. How can a string be converted to a number?

The function takes the string as an input that needs to be converted to an integer.

int atoi(const char *string)

Return Value:

• On successful conversion, it returns the desired integer value


• If the string starts with alpha-numeric char or only contains alpha-num char, 0 is
returned.
• In case string starts with numeric character but is followed by alpha-num char, the string
is converted to integer till the first occurrence of alphanumeric char.
10. How can a number be converted to a string?

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

int sprintf(char *str, const char *format, ...)

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.

Syntax of Recursive Function:

void do_recursion()
{
... .. ...
do_recursion();
... .. ...]
}
int main()
{
... .. ...
do_recursion();
... .. ...
}

12. Why doesn’t C support function overloading?

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

You might also like