Chapter 2 C Programming Basics
Chapter 2 C Programming Basics
Questions:
1. List any four applications of c language.
Features of c-language
2. Extendability
3. Portability
4. Robustness
5. Flexibility
7. Reusability
7. What are the constants? What are the different types of constants inc?
Ans: Constants:If we declare any variable as a constant the value of the variable will not be changed
or modified
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?
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
Ex:
int a;
a=10;
14. What are the different types of variable? What are the rules for naming a variable?
rules for the variable are
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:
double 8 3.123456789123
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.
operators meanings
+ Addition
- Subtraction
* Multiplication
% Percentage
division
20. List the arithmetic operators in c (Or) Explain different arithmetic operations in C programming
language
22. What is meant by operator precedence and state the hierarchy of arithmetic operators?
= ==
25. (1) List and state the hierarchy of logical operators.(2) explain the logical operators in c language
and their precedence.
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.
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
/n Next line
/t Tabular space
/b Back space
/a alarm (beap sound)
/0 Null character
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)
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()
Ans:
printf(): It is used to output function. It is used to display the message or output on the monitor
scanf(): it is used to a input function. It is used to the data from the keyboard at run time.
Syntax:
scanf (control,&var1,&var2);
Eg:
scanf (%d%d,&a,&b);
The value or data read from the keyboard and converts by using the format specifiers and stores into
variable address.
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 inc 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 inc.
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.
50. Describe the use of the conditional operator to form conditional expressions.
51. (1) Explain the functions printf() and scanf(). (Or) explain the syntax
of scanf() () and printf() functions. (2) Explain the role of scanf() and printf() functions.
58. Which of the following are invalid variable names and why?
(9) 123
(10) Short
(11) Hyderabad
(12) Count
(13) Int_rate
Int fact
Float=x, y,z;
Long int, a;
Char ch;d;
Large area;
Long float root1,root2;
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.
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.
***
*****
*******
*********
75. Write a program to print the word C PROGRAM in the following manner.
CP
CPR
CPRO
CPROG
CPROGR
CPROGRA
CPROGRAM
--------------------------------------------------------------------------------------------------------
Interview Questions
C is a structural or high level or middle level language which one is correct answer
Is it possible to execute code even after the program exits the main() function?
What will be printed as the result of the operation below: main() { char *ptr = ? Cisco Systems?; *ptr++;
printf(?%sn?,ptr); ptr++; printf(?%sn?,ptr); }
The following variable is available in file1.c, who can access it?: static int average;
13. What is the difference between while loop and dowhile loop?
In the while loop the condition is first executed. If the condition is true then it
executes the body of the loop. When the condition is false it comes of the loop. In the
dowhile loop first the statement is executed and then the condition is checked. The
dowhile loop will execute at least one time even though the condition is false at the
very first time.
15. How many bytes are occupied by the int, char, float, long int and double?
int - 2 Bytes
char - 1 Byte float - 4 Bytes long int - 4 Bytes double - 8 Bytes
22. What will happen when you access the array more than its dimension?
When you access the array more than its dimensions some garbage value is
stored in the array.
23. Write the limitations of getchar( ) and sacnf( ) functions for reading strings
(JAN 2009)
getchar( )
To read a single character from stdin, then getchar() is the appropriate.
scanf( )
scanf( ) allows to read more than just a single character at a time.
31. What is the output of the following program when, the name given with
spaces?
main()
{
char name[50]; printf(\n name\n); scanf(%s, name); printf(%s,name);
}
Output:
Lachi (It only accepts the data upto the spaces)
33. Why we dont use the symbol & symbol, while reading a String through
scanf()?
The & is not used in scanf() while reading string, because the character variable
itself specifies as a base address.
Example: name, &name[0] both the declarations are same.
34. What is the difference between static and auto storage classes?
Static Auto
Memory
Zero Memory
Local to the block in which Garbage value
Storage the variables is defined Local to the block in which the
Initial value Value of the variable persists variable is defined.
Scope between different function The block in which the
Life calls. variable is defined.
35. What is the output of the program?
main() increment()
{ {
increment(); static int i=1;
increment(); printf(%d\n,i)
increment(); i=i+1;
} }
OUTPUT:
12 3
50. Write a program to swap the values of two variables (without temporary
variable).
#include <stdio.h>
#include <conio.h>
void main( )
{
int a =5; b = 10;
clrscr( );
prinf(Before swapping a = %d b = %d , a , b);
a = a + b; B = a b;
a = a b;
prinf(After swapping a = %d b = %d, a,b);
getch( );
}
Output:
Before swapping a = 5 b = 10
After swapping a = 10 b = 5
51. Write short notes about main ( ) function in C program. (MAY 2009)
Every C program must have main ( ) function.
All functions in C, has to end with ( ) parenthesis.
It is a starting point of all C programs.
The program execution starts from the opening brace { and ends with closing brace
}, within which executable part of the program exists.