0% found this document useful (0 votes)
82 views

CTSD Assignment

The document provides answers to 34 questions about C programming concepts and syntax. It covers topics such as the year C was developed, data types, variables, operators, functions, program structure, preprocessor directives, and more. For each question, the corresponding answer is provided.

Uploaded by

Bittu raja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

CTSD Assignment

The document provides answers to 34 questions about C programming concepts and syntax. It covers topics such as the year C was developed, data types, variables, operators, functions, program structure, preprocessor directives, and more. For each question, the corresponding answer is provided.

Uploaded by

Bittu raja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1. In which year was the Traditional C programming language first Developed?

Answer :1972

2. Which format specifier is used to print the values of double type


Answer :%If

3. VariableHow many phases are there in program development cycle ?


Answer :5

4. File manipulation functions in C are available in which header file. i. streams.h


Answer :stdio. h

5. Which of the following is not s keyword of ‘C’ ?


Answer :int

6. How representation for a new line can be done in C program?


Answer :/n

7. Find out on which line no . you will get an error ?


Line 1: void main ( )
Line 2: {
Line 3: print(“\n Hello World”)
Line 4: }
Answer:Line 3
8. Which system programming languages are Typeless?
Answer :B
9. How many keywords are there in C language?
Answer:32
10. Character constants should be enclosed between_____ quotes.
Answer: single

11. In the Testing & Debugging phase, we check whether the writtenCode in the ______ step is
solving the specified problem or not.

Answer :implementation

12.A declaration float a,b; occupies ______of memory ?

Answer :8 bytes

13. C is a ___ language.

Answer:pragraming or highlevel luguage


14. A program which translates a high level language program into a Machine language
program is called ________.

Answer: complier

15. A declaration float a,b; occupies ___ of memory.

Answer:8 bytes

16. The operator && is an example for ___ operator.

Answer: logical

17. Main Function is the major section from where the ________ of theProgram begins. Answer:
excution

18. The C-processors are specified with _________ symbol.

Answer: #

19. Integers are used to store ________ in C language.

Answer: numerical values

20. Write down the rules of naming variables in C language

answer.

1. variables names which begins with a letter or an (-)


2. After the first character variables names can include a letters digit and (-)
3. variable names are case it’s sensitive meaning”my var” are considered different V
4. Variables names should not be C keywords or reversed words(eg:-int, -if, -while etc)
5. Names should be meaningful and Descriptive, helping to convert The process of variable.
6. The maximum length of a variable names Implementation deployment, but a. Common
Profile is to keep Variable name. Relative short And Concerts For Ability.
Ex:for valid variables names :-intage, float _value; char firstname (39);double user balance
21. Elaborate all components of Structure of C language.
Answer:The components of the structure of C language , which includes. A)Functions, B)
variables C) data type D) keywords E)Operation. F) control structure G )input / H) header
files I)comments
22. What is constant variable? Write the syntax how to declare andInitialize constant
variable?
Answer: A constant variable is a variable whose values cannot be changed after it’s been
assigned. To declare And. Initiable. a constant variable. You can use the constant
keyword.The syntax
Constdata_type variables _name =value
23. Write a C program to calculate area and perimeter of rectangle
Answer:
#include<stdio.h>
#include<conio.h>
Main()
{
Float length, breadth, area, perimeter;
Printf(“enter the length:”);
Scanf(“%f”,&length);
Printf(“enter the breadth:”);
Scanf(“%f”,&breadth);
Area=length*breadth;
Perimeter =2*(length+breadth);
Printf(“area of rectangle:%f\n”,area);
Printf(“perimetre of rectangle : %f\n”,breadth);
Return 0;
}.
24. Explain in brief History of C Programming Language.
Answer :The C programming was developed by Dennis Ritchie at 1970
It allowed from an earlier programming language called B.C was created to develop the.
Unique operation system and it became widely popular due to its simplicity and Efficiency.
C language is the foundation for the many modern Programming languages.It is Often
referred to as “mother” of programming languages.
25. What is the use of header file #include<stdio.h> and also explain Functions printf and
scanf with an example.
Answer:The #include<stdio.h> is a preprocessor directive. That includes the. Standard input
or output header file in our C program. It provides the functionality for input and output
operation.
1. Printf is a function used to display output to console.ex:int no=65;
Printf(“enter the no is %d”,no);
2. Scanf is a function used to read input from user . And it is also defined as scanning and
storing the header file.ex:int x; Printf(“enter the value :”);
Scanf(“%d”,&x);
26. Explain the following operators in C language i) Relational ii)Logical iii) Conditional
Answer :
1) Relational operators:This is used to compare value and return either true or false
based on comparison.
2) Logical operators :It is used to perform logical operations In boolen values.the
logical operators includes logical AND, logical OR, logical NOT
3) Conditional operators :It is often referred to as theOperator is a short and way to
express and if else statement in a single line. It is in the form of condition. True
expression, false expression.

27. Explain in brief History of C Programming Language.

Answer : The C programming was developed by Dennis Ritchie at 1970


It allowed from an earlier programming language called B.C was created to develop the.
Unique operation system and it became widely popular due to its simplicity and Efficiency.
C language is the foundation for the many modern Programming languages.It is Often
referred to as “mother” of programming languages.
28. What is an assignment operator? Give the general form of an Assignment operator.
Answer :Assignment.or is used to ascend to a variable. The general form of Assignment
Operator is.
Variable=expression
29. Describe the types of operators in C and also write a program to find Addition,
subtraction, multiplication and division of two variables
Answer:Types of operators in C language includes arithmetic operator, logical operator,
relational operator, Bitwise operato,Assignment operator,Don’t decrement operator,
Conditional operator, pointer operator, operator, size of the operator.
#include<stdio.h>
#include<math.h>
main()
{
float n,a,b,sum, product, difference,division ;
printf("enter the value of a:");
scanf("%f",&a);
printf("enter the value of b:");
scanf("%f",&b);
sum=a+b;
difference =a-b;
product=a*b;
division =(a/b);
printf("sum:%f\n",sum);
printf("product:%f\n",product);
printf("difference :%f\n",difference );
printf("division :%f\n",division );
return 0;
}
30. Write a C program that computes the size of int, float, double and Char variables.
Answer :
#include <stdio.h>

Int main() {
Printf(“Size of int: %lu bytes\n”, sizeof(int));
Printf(“Size of float: %lu bytes\n”,sizeof(float));
Printf(“Size of double: %lu bytes\n”, sizeof(double));
Printf(“Size of char: %lu byte\n”, sizeof(char);

Return 0;
}
31. What is the purpose of scanf() and printf() statement ? Write the Guidelines to use
scanf() and printf() functions in C language.
Answer :
In the C programming language, `scanf()` and `printf()` are functions used for input and
output, respectively.

1. `scanf()`: This function is used for input, allowing you to read data from the user or a
file. Its purpose is to receive data and store it in variables. Here are some guidelines for
using `scanf()`:

- Provide format specifiers that match the data you expect to read (e.g., `%d` for integers,
`%f` for floats).
- Ensure proper variable types and use the `&` operator to pass the variable’s address.
- Handle error cases where input doesn’t match the specified format.
- Avoid buffer overflow by specifying the maximum field width using format specifiers.

Example of using `scanf()`:


```c
Int num;
Printf(“Enter an integer: “);
If (scanf(“%d”, &num) == 1) {
// Input successful, ‘num’ contains the entered integer.
} else {
}
2. `printf()`: This function is used for output, allowing you to display data to the user or
write it to a file. Its purpose is to format and display data. Here are some guidelines for
using `printf()`:

- Use format specifiers to format data in the output string (e.g., `%d` for integers, `%f` for
floats).
- Ensure the number and types of format specifiers match the arguments you pass.
- Handle formatting and alignment according to your desired output.
- Escape special characters using backslashes (e.g., `’\n’` for a new line).

Example of using `printf()`:


Int num = 42;
Printf(“The value of num is %d\n”, num);
Both scanf() and printf() are powerful, but they require careful usage to avoid common
programming errors, like buffer overflows and format mismatches.
32. Write a C program to find the largest of three numbers using ternary Operator.
Answer :
#include <stdio.h>
Int main()
{
Int num1, num2, num3, largest;
Printf(“Enter three numbers: “);
Scanf(“%d %d %d”, &num1, &num2,&num3);
Largest = (num1 > num2) ? ((num1 > num3) ? num1 : num3) : ((num2 > num3) ? num2 :
num3);
Printf(“The largest number is %d\n”, largest);
Return 0;
}
33. What is Token? What are the different types of token available in C Language?
Answer:
In C language, a “token” is the smallest individual unit in a program, which cannot be
divided further without losing its meaning. Tokens are the basic building blocks of a C
program and are used to represent various elements of the code. There are several types of
tokens in the C language, including:1.Keywords
2.Identifiers
3.Constants
4.String
5.Operators
6.Punctuation
7.Comments
8.Preprocessor Directives
34. Write and explain the basic concepts of a C program.
Answer :
A C program consists of several basic concepts that are essential to understand. Here are
the fundamental concepts in a C program:
1. **Comments:** Comments are used to provide explanatory notes within the code. They
are not executed by the compiler and help in code documentation. In C, comments can
be single-line (//) or multi-line (/* … */).
Example:
```c
// This is a single-line comment
/* This is a
Multi-line comment */
```
2.**Preprocessor Directives:** Preprocessor directives are commands for the C
preprocessor and start with a ‘#’ symbol. They are used to include header files, define
constants, and perform other preprocessing tasks.
Example:
#include <stdio.h> // Include the standard input-output header file
#define MAX_VALUE 100 // Define a constant
3.**Main Function:** Every C program must have a `main` function, which serves as the
program’s entry point. The `main` function is where program execution begins.
Example:
Int main() {
// Code goes here
Return 0;
}
4 .**Variables and Data Types:** Variables are used to store data. C supports various data
types, including int, float, char, and more. Variables must be declared with a data type
before they are use
Example:
Int age = 25;
Float price = 9.99;
Char grade = ‘A’;
5.**Input and Output:** The `printf` function is used to output data to the console, and the
`scanf` function is used to read in output
Example :
Printf(“Hello, World!\n”);
Int number;
Scanf(“%d”, &number);
6.Operators: C provides various operators for performing operations on data, including
arithmetic operators (+, -, *, /), assignment operators (=), comparison operators (==, <, >),
and logical operators (&&, ||)
Example:
int sum = a + b;
If (x > y) {
// Code here
}
7.Functions: Functions are blocks of code that perform specific tasks. They allow you to
modularize your code for better organization and reusability.
Example:
int add(int a, int b) {
Return a + b;
}
8.Control Structures: Control structures are used to manage the flow of the program. C
supports control structures like if-else, switch, loops (for, while, do-while), and more.
Example:
if (condition) {
// Code to execute if condition is true
} else {
// Code to execute if condition is false
}
35. What is an identifier (variable)? What are the rules to construct Identifier (varible)?
Classify the following as valid/invalid Identifiers. I) num2 ii) $num1 iii) +add iv) a_2 v)
199_space vi) _apple v
Answer:An identifier (or variable) in C is a name given to a program entity, such as a
variable, function, or constant. Identifiers are used to uniquely identify and reference these
entities in the code. Here are the rules to construct valid identifiers in C:
1.An Identifier must begin with an alphabetic character (a to z, A to Z) or an underscore
(_).
2.After the initial character, an identifier can contain alphabetic characters, numeric digits
(0 to 9), and underscores.
3.C is case-sensitive, so uppercase and lowercase letters are considered distinct. For
example, “myVariable” and “myvariable” would be treated as different identifiers.
Now, let’s classify the given examples as valid or invalid identifiers:
1)Num2 – Valid
2)$num1 – Invalid
3)+add – Invalid
4)a_2 – Valid
5)199_space – Invalid
6)_apple – Valid
36. Briefly explain data types in C language.
Data type in C language is to define the type of data that variable can hold. That specifies
the size and format of the data, allowing the compiler to allocated memory and perform
operation accordingly.
1) Int: used for integral values.
2) Float:Used for single precision floating point number.
3) Double: Used for double precision floating point numbers.
4) Char:User for. Single characters like digits letters and symbols
5) _bool:A Bolen data type Represents the true or false
6) Long:used for larger integers, providing a width range compared to int
7) Short:Used for Smaller integers taking less memory compared to int
8) Unsigned:Can be applied to int, char, short or long to represent only non negative
values.

37. Define variable. Explain the rules for constructing variables in C Language

Answer :A variable in C is named storage location in memory that holds a value. Rules for
constructing variables in C

1) after the first character Can contain letter, digits, or an underscore


2) Variables are names case sensitive, so my var and myVar and treated as different
variables
3) Variables name should not exist a certain length which varies by compiler but is often
in the range of 31 to 63 characters.
4) Variable names cannot be C keywords or. Reverse words.

38. Explain all phases of program development in C with suitable flow chart

Answer:

Problem Definition→Algorithm design→ coding→ compilation→linking→testing and


debugging→Documentation→Maintenance

39. Define i)variable ii) Constant iii) Associativity iv)Precedence

Answer :

1) Variable:A named storage location in memory that holds a values and can be modified
during program execution
2) Constant:A value that does not change during program execution and is assigned a
fixed value
3) Associativity:The order in which operators of the some precredence are allowed it can
be left to right or right to left
4) Precedence:The priority of operators with higher precedents are allowed first.

40. What are the formatted input and output functions? Explain with Examples.

I formatted input and output. Functions in C are used for reading and writing data Is
specific format. This function allows you to control the formatting of data while reading
from our. Writing to the console or files. Two commonly used functions for formatted input
and output are printf ()and scanf()

Example for printf() is

Int num=10;

Printf(“the value of num is %d\n”,num);

Examples for scanf() is

Int input;

Printf(“enter the number:”);

Scanf(“%d”,&input);

41. Explain with example, the various constants available in ‘C’ language.

Answer:

Constants in C :C language provides various types of constants including,

1)Integer constants:eg.123,-45

2)Floating constants:eg.3.14,-0.10

3)character constant:eg.A,5

4)strings constants:eg.hello world

5)enumeration constants:eg.enum color like red ,blue

6)symbolic constant : defined using # design

Eg. #define pi:3.14159

42. Differentiate between Logical operators and Bit-wise operators.

Answer :

Logical operators :logical operators are used to perform logical operations (AND, OR, NOT)
on boolean expression. The return either ture or false

Ex:int a=1,b=0;

If(a&&b) {//this condition is false

}
Bitwise operators :Bitwise operators are used to perform operation at the bit level. The
work with individuals bits of integer value for example, you can use and for bitwise or so on
ex:int x=5;//bimary is 0101

Int y=3;//binary is 0011

Int result =x&y//result is 1 in binary 0001

43. What is preprocessor directive? Explain #define and #include Preprocessor directives?

Answer:Preprocessor derives our special instruction to the c preprocessor. Which is a tool


that processes the source. Code before Compilation.Two Common. Preprocessor derives

#define:-Used to create symbolic constant or. Marcos.ex:#define PI 3.14159

#include:-Used to include header file in your code.ex:#include<stdio.h>

44. What is the valid range of numbers for int type of data?

Answer:

Valid range of int type :The valid range of int type in C may vary depending on the system
and Compiler. Being used. However in most system .The int type is a 32 bits integer. Which
can represents value in the range approximately -2,147,483,648 to 2,147,483,647 . This
range may be different on system with different. Word size are compiler .You can check the
specific range for your system range. The Limited. Header which provides constant like
intmin and int max

You might also like