[#20] – Introduction to C Programming Language – Questions

C is a general purpose, high-level programming language. Brian Kernighan and Dennis Ritchie created it at AT&T Bell laboratories in 1972 for writing the UNIX operating system.

Although developed between 1969 and 1973, its first publication occurred in 1978 in the form of a book titled “The C Programming Language”. Several programmers preferred C to other programming languages of that time like PL/1, ALGOL, COBOL, FORTRAN, PASCAL and APL. Soon C became the most popular programming language.

The popularity of C is due to its following features:

  1. It is reliable, simple and easy to use.
  2. It has the virtues of a high-level programming language with the efficiency of an assembly language.
  3. It supports user-defined data types of grater flexibility in programming.
  4. It supports modular and structured programming concepts. That is, while writing a C Program to solve a problem, the problem may be broken into smaller tasks, a function may be written to solve each task, and the C program may become a group of functions that are linked to produce the problem solution.
  5. It supports a rich library of functions that can be used directly by programmers to code efficiently their applications.
  6. It supports pointers with printer operations. This feature allows programmers to access memory addresses directly where variables are stored, and to perform bit-level manipulation of data stored in memory or processor registers.
  7. It provides low-level memory and device access features, making it suitable for writing system programs.
  8. It is a small and concise language providing only the bare essential features, so that a C program can be translated by a compiler into an efficient machine language code.
  9. It is standardized by several international standards body, making C Programs easily portable from one computer to another.

Also Read:

Points To Remember:

  • C is a general purpose, high-level programming language developed by Kernighan and Ritchie at AT&T Bell Labs between 1969 and 1973.
  • C has several attractive features that make it one of the most popular programming languages.
  • C character set includes uppercase and lowercase alphabets, digits, and several special characters. Altogether there are 93 valid characters allowed in C.
  • The three primitive types of constants supported in C are integer, real, and character.
  • A C variable is an entity whose value may vary during program execution. C makes it compulsory to declare the type of any variable name that a programmer wishes to use in a program before using it. The basic data types that can be used for such declaration are int, short, long, float, double, and char. Variable names must be unique in their visibility scope.
  • Variable can be accessed only within its visibility scope. A variable is visible in the function or statement block it is declared in. Global variables are accessible from anywhere in program. A local variable has access precedence over global variable of same name.
  • There are 32 keyboards (reserved words) in C. They cannot be used as variable names.
  • C has a wide range of basic operators categorized into arithmetic, logical, bitwise, data access and miscellaneous. Operators have a precedence level and associativity that govern in what order compilers execute them.
  • C program logic is combination of statements. Statements are always found between {} braces called body of a function. Each statement performs a set of operations. Simple statements are terminated by semicolon “;”.
  • C provides standard library functions for performing all input/output operations. Some basic I/O library functions are getch, getche, getchar, putchar, putch, scanf, printf, gets, and puts.
  • Preprocessor directives are source-code preprocessing stage where programmers can provide instruction and declarations that are useful for compiler when processing the source code. Three commonly used preprocessor directives in C are #define, #include, and #ifdef.
  • The pointer data type is special modifier of any other data type that associates value and address of the storage to a variable name. A pointer is declared by adding an ‘*’ symbol after the data type declarator.
  • For a pointer variable, using ‘*’ refers to the value at memory location pointed by it. The name of the pointer variable refers to the address itself. It is possible to get the address of any variable by simple qualifying the variable with & operator.
  • An arrary is a collection of elements in which all elements are of the same data type. It is homogeneous, linear, and contiguous memory structure. An array has a fixed number of elements, called it length or size, given at the time of its declaration. The size parameter must be a numeric literal or a constant. All elements of an array are stored in contiguous memory locations.
  • The elements of an array can be referred to be using their subscript or index position that in monotonic in nature. The first element of an array is always denoted by subscript value of 0(zero), increasing monotonically up to one less than declared size of array.
  • A string is a one-dimensional array of characters terminated by a null character (‘0’). Individual elements of a string can be accessed by using their subscript or index position, with zero being the subscript of the first element.
  • A structure is a program defined data type that is made by using primary data types and other user defined data types. All elements of a structure, also called member variables, are publicly accessible. Each member can be accessed by using “.” (dot) operator. Structure has contiguous memory allocation.
  • A union is a program defined data type that refers to a memory location using several data types. Each data member begins at the same memory location. The minimum size of union variable is the sizes of its largest constituent data types.
  • The if group of conditional branch statements are used to implement simple one-way test. The flow of execution depends on a logical Boolean expression.
  • The switch..case facilitates multi-way condition test similar to if construct when primary test object remains same across all condition tests. Each case constant expression is compared against switch integral expression. A special case named default can be written at the end that is automatically selected if no other case statement is selected.
  • The break statement causes unconditional exit form for, while, do, or switch constructs.
  • The continue statement causes unconditional transfer to next iteration in a for, while, or do constructs.
  • The goto statement causes unconditional transfer to statement marked with the label within the function.
  • The return statement causes immediate termination of function in which it appears and transfers control to the statement that called the function.
  • The for pretest loop statement has three parts; initializer, loop condition, and incrementor. Initializer is executed at start of loop. Loop condition is tested before each iteration. If condition evaluates to nonzero (true) the next iteration occurs otherwise the loop is terminated.
    Incrementor is executed at end of each iteration.
  • The while pretest loop statement has a loop condition. Loop condition is tested before each iteration. If condition evaluates to nonzero (true) the next iteration occurs otherwise the loop is terminated.
  • The do..while posttest loop statement has a loop condition. Loop condition is tested after each iteration. At least one iteration occurs before the condition is tested. If condition evaluates to nonzero (true) the next iteration occurs otherwise the loop is terminated.
  • Functions are building blocks of a program, and are also called subprograms. All function need to be declared and defined before use. Function declaration requires function name, argument list, and return type. Function definition requires coding the body or logic of function. It is possible to declare and define a function at same time.
  • Every C program is required to have a special function called main. This function is the entry point of the program.

List of Questions:

  1. Trace history of development of C language and various standardizations it went through.
  2. Why C is one of the most popular programming languages?
  3. Write the rules for constructing integer constants.
  4. Write the rules for constructing real constants in exponential form.
  5. Write the rules for constructing real constants in fractional form.
  6. Write the rules for constructing variable names.
  7. What are keywords (reserved words)? Write ten keywords used in C language.
  8. What is a comment statement? How a comment statement is written in C? How a comment statement is treated by a compiler?
  9. Write five standard library functions provided in C for performing I/O operations.
  10. What is preprocessor directive?
  11. Explain purpose of following preprocessor directives: #define, #ifdef, #include.
  12. What is primitive data type? What is user defined data type? Give an example of each type.
  13. What are the differences between signed and unsigned data type?
  14. What is a variable? List the restrictions that apply in selecting name for a variable.
  15. What are declaring and defining stages of a variable? How are they different?
  16. What is meant by lifetime and visibility scope of variable?
  17. What is a pointer? How it is declared and used in a C program?
  18. What is the function of ‘*’ and ‘&’ operators in context of pointer variable?
  19. What are important properties of an array in C? How is an array declared in C?
  20. Explain use and characteristics of index or subscript in array?
  21. What is a struct in C? How is a struct declared in C?
  22. Explain how elements of struct are accessed in C?
  23. What is ‘shallow copy’ in struct?
  24. What is a union in C? How is a union declared in C?
  25. What is the difference between structures and unions in C?
  26. What types of basic operators are provided in C? Give an example of each type.
  27. What is operator precedence and associativity?
  28. Explain, with example, if..else control construct in C?
  29. How is switch different from if group of control constructs in C? Give one example where same logic can be written in both if and switch constructs.
  30. What is significance of break keyword in switch construct? What will be behavior of a switch block having no break statement? Explain with an example of your own.
  31. What is effect of writing a continue statement in a loop? Explain with an example.
  32. What is a pretest loop? What is a posttest loop?
  33. What are different parts of a for construct? What is behavior of a for loop where these parts are not provided?
  34. How is while loop different from do..while loop? Write a loop logic of your own using both these loop constructs.
  35. What are functions? Write the general syntax for declaring a function?
  36. What is return used of in a C function?
  37. What is the significance of main function in C?
  38. What is the prototype of main function in C?
  39. Write a C program to accept five numbers from console and then to display them back on console in ascending order.
  40. Write a C program to calculate the sum of all numbers from 0 to 100 (both inclusive) that are divisible by 4.
  41. Write a C program to accept the length of three sides of a triangle from console and to test and print the type of triangle – equilateral, isoceles, right angled, none of these.
  42. Write a C program to accept a string from console and to display the following on console:
    Total number of characters in the string
    Total number of vowels in the string
    Total number of occurrence of character ‘a’ in the string.
    Total number of occurrence of string ‘the’ in the string.
You may also like:

Related Posts

Leave a Reply