Chapter 2 C Programming Basics
Questions:
/*Note: I gave the answers some of the questions, some of the questions i could not type here, i will post later */
1. List any four applications of ‘c’ language.
2. Write any four important features of ‘c’ language.
Ans:
Features of c-language
1. Modularity(Structure Oriented or Function oriented)
2. Extendability
3. Portability
4. Robustness
5. Flexibility
6. Fast execution (speed)
7. Reusability
For more information click on
C Features
3. Write the character set of c programming language.
Ans: To see the answer click on Character set
4. List C
Tokens.
5. Describe the different types of tokens used in ‘c’.
6. List the various types of data in c and give examples.
7. What are the constants? What are the different types of constants in’c’?
Ans: Constants:If
we declare any variable as a constant the value of the variable will not be
changed or modified
Syntax: Data
type const variable=value;
8. (1) List and explain the four basic types of constants in ‘c’. (2) List the basic data types available in c language and give example for each.
Ans:Data type
9. What is the character constant? How do characters constant differ from numeric constants? Do character constants represent numeric values?
10. What is a string constant? How do string constants differ from character constants? Do string constants represent numeric values?
11. What is a key word? List at least four key words in c.
Ans:
Keywords: At
the time of designing the c-language some words are used to do a specific task
called keywords. There are 32 keywords are available in c-language.
EX: int,float,char,double,unsigned,auto,const,while,if,do,else,static,long, short, register signed, default, static,
for,break,continue,goto, volatile , extern etc…..,
12. What is a variable? What are the rules for naming a variable? (Or) what are the rules to be observed in naming an identifier in c?
Ans: 1. Variables:An
variable is an identifier(user defined word) It is used to store the data the
variable can stores one value
Syntax: datatype variable;
Ex:
int a;
a=10;
Rules for the Identifier :
1.It should starts with alphabetical letters only
2.It should not starts with numerical values, special symbols.
3.It should not exit more than 32 characters.
4. Keywords are not used as variables.
14. What are the different types of variable? What are the rules for naming a variable?
rules for the variable are
1.It should starts with alphabetical letters only
2.It should not starts with numerical values, special
values.
3.It should not exit more than 32 characters.
4. Keywords are not used as variables.
15. Explain the declaration of variables in detail.(Or) what is the purpose of type declaration?
16. (1) List and explain the four basic (primary) data types in ‘c’.(Or) name the different fundamental data types that C supports and explain them in detail.(2) explain different data types in c-language with examples. How are constants declared in c- language?
Ans: (a): Basic Data types or Fundamental Data types or Primitive Data types are:
Name of datatype
|
Size
|
Range
|
int
|
2
|
32, 767 to +32,767
|
float
|
4
|
7.8390 with 6decimal
|
char
|
1
|
-128 to +127
|
double
|
8
|
3.123456789123…
|
long int
|
4
|
-2147483648 to +21147483648
|
long double
|
10
|
3.4E-4932 to 1.1E+4932
|
The Constants are declare as below:
Syntax: const datatype variable=value;
const int a=10;
17. Classify data kinds in c and explain the primary data types in c with examples. (Or) discuss in detail about various kinds of data manipulated by a computer program.
18. List the arithmetic operators in c.
Ans:
operators
|
meanings
|
+
-
*
%
÷
|
Addition
Subtraction
Multiplication
Percentage
division
|
19 operators and Expressions
19. What is an Operators? Describe several different types of operators included in ‘c’.
20. List the arithmetic operators in c (Or) Explain different arithmetic operations in C programming language
21. What is meant by operator precedence and associativity of an operator?
Ans:
For operators, associativity means that when the same operator appears in a row, then to which direction the evaluation binds to. In the following,
Usually + and - have the same precedence. Consider the expression 7 − 4 + 2. The result could be either (7 − 4) + 2 = 5 or 7 − (4 + 2) = 1. The former result corresponds to the case when + and − are left-associative, the latter to when + and - are right-associative.
22. What is meant by operator precedence and state the hierarchy of arithmetic operators?
23. What is the precedence of relational operators in C language?
24. Differentiate between ‘=’ and’==’ in C language.
=
|
==
|
1. It is a assignment operator
|
1.it
is a relational operator
|
2. It is is used to assign the value
to the variable
Eg:
int a=10;
|
2. It is used to compare the value to the left hand side variable.
Eg :
int a=5;
a=10;
|
3.The
value 10 is string into the variable a
|
3.The
value 10 is compare to the left hand side variable.
|
25. (1) List and state the hierarchy of logical operators.(2) explain the logical operators in c language and their precedence.
26. What is the modulus operator and how does it work in ‘C’?
27. What is meant by assosiativity? What is the assosiativity of the arithmetic, relational and logical operators?
28. Define an expression and show how to evaluate an expression with an example.
29. With the help of an example explain how a logical expression is evaluated.
30. Name and describe relational, logical and assignment operators.
31. Summarize the standard escape sequences in C.describe them.(or) what is an escape sequence? What is its purpose? List the standard escape sequences in C.
Ans: Escape sequences is consider as character motion . it is also known as
back slash character
Escape sequences
|
Meaning
|
/n
|
Next line
|
/t
|
Tabular space
|
/b
|
Back space
|
/a
|
alarm (beap sound)
|
/0
|
Null
character
|
32. List assignment or compound operators in C.
33. Explain any four assignment operators with examples.
34. What is a unary operator? List the various unary operators in C.
35. What are the commonly used input/output functions in C? How are they accessed? (Or) explain input and output in C language with examples.
(or)
List and give the syntax of I/O statements used in C.
Ans:Input output
statements in c
Input and output functions are divided into two parts
1. Formatted
functions
2. Unformatted
functions
Again formatted and
unformatted functions are divided into few types
They are:
Formatted functions:
printf()
scanf()
Unformatted functions:
putchar()
getchar()
puts()
gets()
37. Describe the formatted input and output functions.
Ans:
printf(): It
is used to output function. It is used to display the message or output on the monitor
It is a call by value function. It is predefined in
<stdio.h>
Syntax: printf(“control string”, variable);
printf(“message”);
scanf(): it
is used to a input function. It is used to the data from the keyboard at run
time.
It is
also predefined in <stdio.h>
Syntax:
scanf
(“control”,&var1,&var2);
Eg:
scanf
(“%d%d”,&a,&b);
It is call by address function.
The value or data read from the keyboard and converts by
using the format specifiers and stores into variable address.
38. List the commonly used math library functions in C.
39. Explain the usage of comma operator. (Or) what is comma operator? Explain its syntax with suitable example.
40. Explain the pre increment and post increment operators’ in’c’ with examples.
41. (1) Explain increment and decrement operators in C language with examples. (Or) illustrate the usage of increment and decrement operators in detail. (2) Differentiate between pre increment/decrement operators and post increment/decrement operators in’c.
Ans:increment
and decrement operators
42. (1) State the importance of (a) increment and decrement operators (b) conditional operators.
43. List the various type conversion techniques used in C and explain them in brief.
44. Distinguish between getch (), and getchar () functions with suitable examples.
45. Explain the following (1) increment and decrement operators (2) assignment operators (3) arithmetic operators (4) relational operators.
46. What is conditional (ternary) operator? Explain with an example.
49. Explain the pre processor features(1)#include(2)#define
50. Describe the use of the conditional operator to form conditional expressions.
52. How comments can be included within a C program?
53. Why is the main () function special in a C program?
54. List any four standard headers that can be included in c.
56. What is a null statement in C language?
57. Explain the null statement and coma operator.
58. Which of the following are invalid variable names and why?
(1) Profit (14) counter-3
(2) Last name (15) annual report
(3) 2002INCOME (16) TOTAL-REVENUE
(4) dist. (17) engg.college
(5) Float (18) last-named
(6) #tax (19) -count
(7) Stud add (20) $balance
(8) 2nd_strret (21) new-word
(9) 123
(10) Short
(11) Hyderabad
(12) Count
(13) Int_rate
59. Find errors, if any, in the following declaration statements
Int fact
Float=x, y,z;
Long int, a;
Char ch;d;
Large area;
Long float root1,root2;
60. Convert the following equations into corresponding C statements
Ans:
(v):
-b+sqrt b*b-4*a*c/2*a
-b-sqrt b*b-4*a*c/2*a
61. Evaluate the expression (A/B-C+A%B) for A=20, B=4, C=2 by following operator hierarchy.
62. Write a program to ready any two floating-point numbers from the keyboard and to display their addition, subtraction, multiplication and division.
63. (i) Write a C program to accept five real numbers from the keyboard and to find out their sum and average. (ii) Write a C program to calculate average of three numbers.
64. Write a C program to calculate the total marks and the percentage marks obtained by the student in five subjects. Assume that the maximum marks that can be obtained by the student in each subject is100.
65. Write a program to calculate the perimeter and area of a rectangle.
66. Write program that calculate area of the triangle given the base and the height.
67. Two numbers are input through the keyboard into two locations Cand D .write a program to interchange the contents of C and D.
68. Write a c program to convert temperature degrees into centigrade to degrees Fahrenheit.
69. Write a program that calculates the volume and surface area of the sphere, given the radius.
70. Write a C program to read an integer number of days and convert it into months and days.
71. Write a program to calculate the simple interest and compound interest for a given principle (p), rate of interest(r), time (t) and compounding per year (n) using the formulas
72. Write a program that demonstrate the difference between predecrementing and post decrementing using the decrement operator.
73. Write a C program to find the largest of two numbers using conditional operator.
74. Write a C program to print the following.
*
***
*****
*******
*********
75. Write a program to print the word “C PROGRAM” in the following manner.
C
CP
CPR
CPRO
CPROG
CPROGR
CPROGRA
CPROGRAM
--------------------------------------------------------------------------------------------------------