0% found this document useful (0 votes)
23 views10 pages

Programming in C - CS3251 - Important Questions With Answer - Unit 1 - Basics of C Programming

The document outlines the syllabus for the 2nd semester of the Computer Science & Engineering program at Anna University, including various subjects such as Professional English, Engineering Graphics, and Programming in C. It provides a detailed question bank for the Programming in C course, covering topics like data types, operators, control statements, and functions. Additionally, it includes example questions and answers related to C programming concepts and practices.

Uploaded by

RajKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Programming in C - CS3251 - Important Questions With Answer - Unit 1 - Basics of C Programming

The document outlines the syllabus for the 2nd semester of the Computer Science & Engineering program at Anna University, including various subjects such as Professional English, Engineering Graphics, and Programming in C. It provides a detailed question bank for the Programming in C course, covering topics like data types, operators, control statements, and functions. Additionally, it includes example questions and answers related to C programming concepts and practices.

Uploaded by

RajKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

All 2nd Semester Subjects

Professional English - II - HS3252 Engineering Graphics - GE3251


Statistics and Numerical Methods - Physics for Electronics Engineering -
MA3251 PH3254
Physics for Electrical Engineering - Physics for Civil Engineering - PH3201
PH3202
Materials Science - PH3251 Basic Electrical and Electronics
Engineering - BE3251
Physics for Information Science - Basic Civil and Mechanical Engineering -
PH3256 BE3255
Basic Electrical and Instrumentation Electric Circuit Analysis (Circuit
Engineering - BE3254 Theory) - EE3251
Programming in C - CS3251 Circuit Analysis - EC3251
Data Structures Design - AD3251
4931_Grace College of Engineering,Thoothukudi www.BrainKart.com

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

BE- Computer Science & Engineering

E
Anna University Regulation: 2021

O
C
CS3251- Programming in C
E
I Year/II Semester
AC

Question Bank
R
G

Unit- I Basics of C Programming

Prepared By,
Ms. S. Abarna, AP/CSE

CS3251_PIC https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 1 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
BASICS OF C PROGRAMMING
Introduction to programming paradigms – Applications of C Language - Structure of C program - C
programming: Data Types - Constants – Enumeration Constants - Keywords – Operators:
Precedence and Associativity - Expressions - Input/Output statements, Assignment statements –
Decision making statements - Switch statement - Looping statements – Preprocessor directives -
Compilation process

UNIT-I / PART-A
1. What are the different data types available in “C”? (May 14)
There are four basic data types available in C.
 int
 float
 char
 double
2. What is an Operator, Operand and Keywords?
 Operator
 An operator is a symbol that specifies an operation to be performed on operands.

E
Example: *, +, -, / are called arithmetic operators.
 Operand
 The data items that operators act upon are called operands. Example: a+b; In this

O
statement a and b are called operands.
 Keywords C
 Keywords are certain reserved words that have standard and pre-defined
meaning in C. These keywords can be used only for their intended purpose.
3. Define Constants in C. Mention the types.
The constants refer to fixed values that the program may not alter during its execution.
E
These fixed values are also called literals. Constants can be of any of the basic data types
like an integer constant, a floating constant, a character constant, or a string literal. There
AC

are also enumeration constants as well. The constants are treated just like regular
variables except that their values cannot be modified after their definition.
4. What are Ternary operators or Conditional operators? (or) Give an Example for
Ternary operator. (Nov/Dec 14)
Ternary operators is a conditional operator with symbols ? and :
R

Syntax: test ? expression1 : expression2


 test-Any Boolean expression.
G

 expression1-An expression returned if test is true.


 expression2-An expression returned if test is false.
#include<stdio.h>//Header File
void main()//Main function of every C program
{
int a,b,c;
clrscr();
printf("Enter the values of a and b:");
scanf("%d%d" ,&a,&b
c = a>b ? a : b; //Ternary operator
printf("Larger number=%d" ,c);
}
Output
Enter the values of a and b:30 90
Larger number=90

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 2 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
5. What are the Bitwise operators and logical operators available in C ?
 Bitwise operators
 Bitwise AND, | - Bitwise OR, ~ - One„s Complement, >> - Right shift, << - Left
shift,
 ^ - Bitwise XOR are called bit field operators.
 Example: k=~j; where ~ take one„s complement of j and the result is stored in k.
 Logical operators
 The logical operators available in C are &&- Logical AND, || - Logical OR, ! -
Logical NOT
6. What is a Variable? Illustrate it with an example. (Nov/Dec 14)
 A variable is a data name used for storing a data value.
 Can be assigned different values at different times during program execution.
 Can be chosen by programmer in a meaningful way so as to reflect its function in the
program.
 Example: int i, num; //i, num are variables that can store integer values
7. What is the difference between Logical AND and Bitwise AND?
 Logical AND (&&): Only used in conjunction with two expressions, to test more

E
than one condition. If both the conditions are true the returns 1. If false then return 0.
 AND (&): Only used in Bitwise manipulation. It is a unary operator.

O
8. What is the importance of keywords in C. (May 15)
C programs are constructed from a set of reserved words which provide control and
from libraries which perform special functions. The basic instructions are built up using
C
a reserved set of words, such as main, for, if, while, default, double, extern, for, and int,
etc., C demands that they are used only for giving commands or making statements.
9. What is type casting?
E
Type casting is the process of converting the value of an expression to a particular data
type.
Example:
AC

int x, y; c = (float) x/y; where a and y are defined as integers. Then the result of x/y is
converted into float.
10. What are various types of C operators? (Jan 14)
 Arithmetic Operators
R

 Increment and Decrement Operators


 Assignment Operators
 Relational Operators
G

 Logical Operators
 Conditional Operators
 Bitwise Operators
11. What are the main features and applications of C language? (Jan 11)
C is case sensitive language.
 Modularity: we can split the C program into no. of modules. It allows reusability of
modules.
 Middle level language: as a middle level language C combines both the advantages
of low level and high level languages. (arrays, pointers etc). Efficient Use of Pointers
 General purpose programming language: C can be used to implement any kind of
applications such as math‟s oriented, graphics, business oriented applications.
 Portability: we can compile or execute C program in any operating system
(unix,dos,windows).
 Powerful programming language: C is very efficient and powerful programming
language, it is best used for data structures and designing system software.

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 3 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
12. What is the difference between while loop and do…while loop? (or) Differentiate
Entry and Exit controlled constructs. (Jan 13)
While do-while
Its an entry controlled loop Its an exit controlled loop
In the while loop the condition is first In the do…while loop first the statement is
executed. If the condition is true then it executed and then the condition is
executes the body of the loop. When the checked. The do…while loop will execute
condition is false it comes of the loop at least one time even though the condition
is false at the very first time
Syntax: Syntax:
while(condition) do
{ {
//body of the loop //body of the loop
} } while(condition);
13. What is a Modulo Operator? What is the use of sizeof( ) operator?
 Modulo Operator
„%‟ is modulo operator. It gives the remainder of an integer division

E
o Example: a=17, b=6. Then c=%b gives 5.
 Sizeof( ) operator

O
 The sizeof ( ) operator gives the bytes occupied by a variable.
 No of bytes occupied varies from variable to variable depending upon its data
types.
Example:
C
int x,y;
printf(“%d”,sizeof(x));
E
Output: 2
14. Define with example integer and floating type of data in C language. (Jan 11)
AC

 The int is used to define integer numbers. An integer occupies 2 bytes memory
space and its value range limited to -32768 to +32767 (that is, -215 to +215-1)
Example: int count=5
 The float is used to define floating point numbers. The float data type is used to
store fractional numbers (real numbers) with 6 digits of precision. Floating point
R

numbers are denoted by the keyword float.


Example: float miles = 4.5
15. What are the I/O Functions in C? (May 15, Jan 16)
G

 Formatted I/O Statements


 scanf(),printf()
 Unformatted I/O Statements:
 getchar(), putchar(), gets(), puts()
16. What is the difference between ++a and a++?
 ++a means do the increment before the operation (pre increment)
 a++ means do the increment after the operation (post increment)
Example:
a=5;
x=a++; /* assign x=5 but „a‟ value is incremented to 6*/
y=a; /*now y assigns y=6*/
x=++a; /*assigns x=7 and a value is incremented to 7*/
17. Construct an infinite loop using while?
while (1){ }
Here 1 is a non zero, value so the condition is always true. So it is an infinite loop.

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 4 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
18. What is a program?
A program is a set instruction written to carry out a particular task, so that computer can
perform some specified task. Example program to find sum of 2 numbers
#include<stdio.h>
void main()
{ int a, b, sum;
printf("\nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
}
Output : Enter two no: 5 6
Sum : 11
19. What is a global variable?
The global variable is a variable that is declared outside of all the functions. The global
variable is stored in memory, the default value is zero. Scope of this variable is available
in all the functions. The variable is live as long as the program terminates.

E
Example:
#include<stdio.h>

O
int a,b; //a,b are global variables
main()
{...} C
20. What are the Escape Sequences present in “C”?
Escape Sequence Symbol Escape Sequence Name
\n New Line
E
\t Tab space
\r Carriage return
\f Form feed
AC

21. Write the limitations of getchar( ) and scanf( ) functions for reading strings
 getchar( )-To read a single character from stdin, then getchar() is the appropriate.
 scanf( ) allows to read more than just a single character at a time. In scanf() when
there is a blank was typed, the scanf() assumes that it is an end
R

22. What is the difference between scanf() and gets() function?


In scanf() when there is a blank was typed, the scanf() assumes that it is an end.scanf()
accepts any datatype using appropriate format specifier. gets() assumes the enter key as
G

end. That is gets() gets a new line (\n) terminated string of characters from the keyboard
and replaces the „\n‟ with „\0‟. It accepts the input as only strings
23. Define Compilation, linking process? (or) What is meant by Linking process. (Jan 16)
 Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the
creation of an 'object' file. This step doesn't create anything the user can actually run.
Instead, the compiler merely produces the machine language instructions that
correspond to the source code file that was compiled.
 Linking refers to the creation of a single executable file from multiple object files. In
this step, it is common that the linker will complain about undefined functions
(commonly, main itself). During compilation, if the compiler could not find the
definition for a particular function, it would just assume that the function was
defined in another file. If this isn't the case, there's no way the compiler would know
it doesn't look at the contents of more than one file at a time. The linker, on the other
hand, may look at multiple files and try to find references for the functions that
weren't mentioned.

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 5 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
24. Write a C Program to find factorial of a given number using iteration.
#include<stdio.h>
int main()
{
int i=1,f=1,num;
printf("Enter a number: ");
scanf("%d",&num);
while(i<=num)
{
f=f*i;
i++;
}
printf("Factorial of %d is: %d",num,f);
return 0;
}
Output:
Enter a number: 5 Factorial of 5 is 120

E
25. Write a for loop statement to print numbers from 10 to 1. (Jan 14)
for( i=10;i>=1;i--)

O
printf(“\n%d”,i);
26. List some preprocessor directives in C.(Jan14, 16)
 Macro Replacement Directive (#define,#undef)
C
 Source File Inclusion Directive (#include)
 Line Directive (#line)
 Error Directive (#error)
E
27. Give the rules for defining preprocessor.
 # pound symbol used before preprocessor directive
AC

 # must be first character in source file or first non white space character in a line
 New line character ends preprocessor directive
 Only single space/tab space allowed between preprocessing tokens
 Can appear anywhere in program but generally paced in beginning of program
 The preprocessor cannot have termination with semicolon.
R

28. What is meant by storage class?


Every C variable has a storage class and a scope. The storage class determines the part of
memory where storage is allocated for an object and how long the storage allocation
G

continues to exist. It also determines the scope which specifies the part of the program
over which a variable name is visible, i.e. the variable is accessible by name. The
following are the storage classes which can be used in a C Program.
 auto ,register ,static and extern
29. Define Static Storage Class (Dec 14)
Storage class specifier static specifies that the declared object can be used both in local
scope and global scope. Static variable/object has a value throughout the execution of
the program and the object will be saved in main memory
Example: static int a;
30. What is meant by Preprocessor Directives?
 Preprocessor is controlled by directives (commands) known as Preprocessor
Directives
 Preprocessor directives are not part of C language
 It consists of various preprocessing tokens
Begins with pound symbol(#)

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 6 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
31. Difference between Storage class and data type
Data type Storage class
It refers to the type of information It refers to the scope and lifetime of
the
represented by a variable variable within the program
Example: int, char, float Example: register, static, extern
32. What is the use of pre-processor directives? (May 14,15, 19)
 It makes programs easier to develop,
 easier to read,
 easier to modify
 C code more transportable between different machine architectures.
33. What is the use of #define processor? (Dec 14)
#define directive is used to define Macros –which are tokens that can be replaced for
user defined sequence of characters
Syntax: #define macro-name replacement-list
Example: #define PI 3.14
34. What is enumeration constant?

E
An enumeration is a list of constant integer values, as in enum boolean {NO, YES}; The
first name in an enum has value 0, the next 1, and so on, unless explicit values are

O
specified. Names in different enumerations must be distinct. Values need not be distinct
in the same enumeration
35. What is external storage class? (May 18)
C
A variable declared with the extern storage-class specifier is a reference to a variable
with the same name defined at the external level in any of the source files of the
program. A variable declared with the extern keyword is visible only in the block in
E
which it is declared
36. How does a pre-processor work? (May 18)
AC

 Preprocessor translator converts high level language program to an equivalent


program in another high language
 Preprocessor is controlled by directives (commands) known as Preprocessor
Directives
R

 Preprocessor directives are not part of C language


 It consists of various preprocessing tokens
 Begins with pound symbol(#)
G

37. Difference between formatted and unformatted input statements.Give one example
for each. (May 19)
 Formatted input : The function scanf() is used for formatted input from standard
input and provides many of the conversion facilities of the function printf().
 Example: scanf(“ %c %d”,&name, &rollNo);
 Unformatted input : Unformatted I/O is the most basic form of I/O and it is simple,
efficient and compact.It is an input stream object in order to read a portion of
information in the form of bytes, without any translation. getchar() and
getch() functions will read a single character from the standard input.
Example: char ch; ch = getchar();
UNIT-I / PART-B
1. (i) Explain in detail about “C” declarations and variables. (Jan 11)
(ii) What are constants? Explain the various types of constants in C. (May 15)
2. Discuss about the various data types in “C”.

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 7 of 8
4931_Grace College of Engineering,Thoothukudi
www.BrainKart.com
3. Explain about the various decision making statements in “C” language. (or) Write notes
on Branching Statements in C. (Jan 14,16 May 14,18)
4. Explain various operators in c with example? (or) Explain the different types of
operators used in C with necessary program. (Dec 14, May 15,18)
5. Explain briefly about the formatted and unformatted I/O function in C. (Jan 12)
6. Explain the different looping statement with example? (or) What is the purpose of
looping statement? Explain in detail the operations of various looping statement with
examples. (Jan 14,16, Dec 14, , May 15, 18, 19)
7. (i) Write a C program to check whether the given number is palindrome or not. (May 18)
(ii) Write a C program to sum of digits of an integer. (Jan 12, May 14)
8. Write a program to solve the Quadratic equation. (May 15)
9. Write a program to find whether a number is prime or not. (May 14)
10. Describe the structure of a C program using “Calculator program” example. (Jan 12)
11. Explain in detail about preprocessor directives with examples.
12. Explain the concept of storage classes with suitable example. (or) What are the Storage

E
classes available in C ? Demonstrate the working of each storage class.(May 14, 19, Jan
16)
13. Write a C program to find the sum of 10 non-negative numbers entered by the user.

O
(May 14)
14. Write a C program to find the largest among 3 numbers entered by the user. (May 19)
C
E
AC
R
G

CS3251_PIC
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Page 8 of 8
All 2nd Semester Subjects
Professional English - II - HS3252 Engineering Graphics - GE3251
Statistics and Numerical Methods - Physics for Electronics Engineering -
MA3251 PH3254
Physics for Electrical Engineering - Physics for Civil Engineering - PH3201
PH3202
Materials Science - PH3251 Basic Electrical and Electronics
Engineering - BE3251
Physics for Information Science - Basic Civil and Mechanical Engineering -
PH3256 BE3255
Basic Electrical and Instrumentation Electric Circuit Analysis (Circuit
Engineering - BE3254 Theory) - EE3251
Programming in C - CS3251 Circuit Analysis - EC3251
Data Structures Design - AD3251

You might also like