100% found this document useful (2 votes)
432 views

Unit 1 CS3353 - C Programming and Data Structures

The document defines various fundamental concepts in C programming such as data types, variables, operators, conditional statements, loops, functions, and arrays. It provides examples to explain these concepts and lists some common operators, conditional statements, and looping constructs available in C. It also provides the syntax for various programming elements like functions, arrays, and loops. Finally, it lists some programming problems and asks to write C code to solve them, focusing on numerical and string processing problems.

Uploaded by

Kokila S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
432 views

Unit 1 CS3353 - C Programming and Data Structures

The document defines various fundamental concepts in C programming such as data types, variables, operators, conditional statements, loops, functions, and arrays. It provides examples to explain these concepts and lists some common operators, conditional statements, and looping constructs available in C. It also provides the syntax for various programming elements like functions, arrays, and loops. Finally, it lists some programming problems and asks to write C code to solve them, focusing on numerical and string processing problems.

Uploaded by

Kokila S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT 1

PART-A
1. List down the Primary Data Types in C
 Integer – We use these for storing various whole numbers, such as 5, 8, 67,
2390, etc.
 Character – It refers to all ASCII character sets as well as the single alphabets,
such as ‘x’, ‘Y’, etc.
 Double – These include all large types of numeric values that do not come
under either floating-point data type or integer data type.
 Floating-point – These refer to all the real number values or decimal points,
such as 40.1, 820.673, 5.9, etc.
 Void – This term refers to no values at all. We mostly use this data type when
defining the functions in a program.
2. What is Variable?
 Variables are containers for storing data values.
 Its value can be changed, and it can be reused many times.
 Syntax for creating variables
 type variableName = value;
 Example: int a = 5;
3. What is Operator?
 An operator is a special symbol that tells the compiler to perform specific
mathematical or logical operations.
 Operators in programming languages are taken from mathematics.
 C language supports a rich set of built-in operators.
4. List the types of operators supported in C
 Arithmetic operators
 Relational operators
 Logical operators
 Bitwise operators
C Programming and Data Structures 1.95

 Assignment operators
 Type Information Operators(Special operators)
5. What is Ternary operators or Conditional operators?
 Ternary operators is a conditional operator with symbols? and :
 Syntax: variable = exp1 ? exp2 : exp3
 If the exp1 is true variable takes value of exp2. If the exp2 is false, variable
takes the value of exp3.
6. What is an Operator and Operand?
 An operator is a symbol that specifies an operation to be performed on
operands.
 Example: *, +, -, / are called arithmetic operators.
 The data items that operators act upon are called operands.
7. What is type casting?
 Type casting is the process of converting the value of an expression to a
particular data type.
 Example: 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.
8. What is the difference between while loop and do while loop?
while do while
In the while loop the condition is first In the do…while loop first the
executed. statement is executed and then the
condition is checked.
If the condition is true, then it executes The do…while loop will execute at
the body of the loop. When the least one time even though the
condition is false it comes of the loop. condition is false at the very first time.

9. 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)
1.96 C Programming Fundamentals

10. What is a Function?


 A function is a block of code which only runs when it is called.
 It performs a specific task.
11. What is meant by Recursive function?
 If a function calls itself again and again, then that function is called Recursive
function.
 The syntax for recursive function
is: function recurse() {
// function code
recurse();
// function code
}
recurse();
12. Write short notes about main() function in ’C’ program.
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.
13. Give the syntax for the ‘for’ loop statement
for (Initialize counter; Test condition; Increment / Decrement)
{
statements;
}
14. What is an Array?
 An array is defined as finite ordered collection of homogenous data, stored
in contiguous memory locations.
 finite means data range must be defined.
 ordered means data must be stored in continuous memory addresses.
C Programming and Data Structures 1.97

 homogenous means data must be of similar data type.


 For example: if you want to store marks of 50 students, you can create an
array for it.
 int marks[50];
15. What are the different types of arrays available in C.
 One-dimensional arrays
 Multidimensional arrays
16. Write short notes on One-dimensional arrays.
 A One-Dimensional Array in C programming is a special type of variable that
can store multiple values of only a single data type such as int, float, double,
char etc.
 The syntax of declaring Two-dimensional arrays is:
 datatype array name [size]
 Example
For example, int a[5]
17. Write short notes on Two-dimensional arrays.
 A multi-dimensional array can be termed as an array of arrays that
stores homogeneous data in tabular form.
 The general form of declaring Two-dimensional arrays is:
 data_type array_name[x][y];
 Example
int x[10][20];
18. What are the key features in the C programming language?
 Portability: It is a platform-independent language.
 Modularity: Possibility to break down large programs into small modules.
 Flexibility: The possibility of a programmer to control the language.
 Speed: C comes with support for system programming and hence it compiles
and executes with high speed when compared with other high-level languages.
 Extensibility: Possibility to add new features by the programmer.
1.98 C Programming Fundamentals

19. What is a nested loop?


 A loop that runs within another loop is referred to as a nested loop. The first
loop is called the Outer Loop and the inside loop is called the Inner Loop. The
inner loop executes the number of times defined in an outer loop.
20. What are the modifiers available in C programming language?
 Short
 Long
 Signed
 Unsigned
 long long
21. What is the explanation for prototype function in C?
 Prototype function is a declaration of a function with the following
information to the compiler.
 Name of the function.
 The return type of the function.
 Parameters list of the function.
 Example
 int sum(int,int);
22. What do you mean by the Scope of the variable?
 Scope of the variable can be defined as the part of the code area where the
variables declared in the program can be accessed directly. In C, all identifiers
are lexically (or statically) scoped.
23. Can a C program be compiled or executed in the absence of a main()?
 The program will be compiled but will not be executed. To execute any C
program, main() is required.
24. What is the main difference between the Compiler and the Interpreter?
Interpreter Compiler
Translates program one statement at a Scans the entire program and translates
time. it as a whole into machine code.
C Programming and Data Structures 1.99

Interpreters usually take less amount of Compilers usually take a large amount
time to analyze the source code. of time to analyze the source code.
However, the overall execution time is However, the overall execution time is
comparatively slower than compilers. comparatively faster than interpreters.
No Object Code is generated, hence are Generates Object Code which
memory efficient. further requires linking, hence
requires more memory.
Programming languages like Programming languages like C, C++,
JavaScript, Python, Ruby use Java use compilers.
interpreters.

PART-B
1. Explain the different types of operators with neat examples.
2. Illustrate the different conditional statements available in C with syntax and examples
3. Explain the looping statements with neat examples.
4. What is an Array? Explain Single and Multi-Dimensional arrays with neat examples.
5. Write a C program for Matrix Multiplication with a 3*3 matrix.
6. Create a C program for Matrix Addition.
7. Write a C program to calculate the total, average and grade for 50 Students.
8. Write a C program to calculate the factorial of a given number.
9. Write a C program to check whether a given number is odd or even.
10. Write a C program to check whether a given number is prime or not.
11. Write a C program to check whether a given number is a palindrome or not.
12. Write a C program to check whether a given number is a Armstrong number or not.

You might also like