Computer Programming C: UNIT I: Introduction to C

Introduction to C: 2 marks Definitions Answers

Computer Programming C

2 marks Definitions Answers, Multiple Choice Questions, True or False

2 marks Definitions Answers

 

• 'C' is one of the most popular programming language, it was developed by Dennis Ritchie at AT & T's Bell Laboratories at USA in 1972. It is an upgraded version of two earlier languages, called BCPL and B, which were also developed at Bell laboratories.

 

• Low level Language: Low level language is in terms of O's and 1's (bits). 'C' language has the certain features of "Low‒level Language", that allows the programmer to carry out operations on bits that are normally available in assembly language or machine language.

 

• High Level language: High level language looks like normal English, whose instruction set is more compatible with human languages. These languages are easily understandable and have been designed to give a better program efficiency.

 

• Preprocessor section: It is used to link system library files, for defining the macros and for defining the conditional inclusion.

Eg: #include <stdio.h>, #define A 10, #if def, #endif... etc.

 

• Keyword: There are certain reserved words called keywords, that have standard and predefined meaning in 'C' language. Which cannot be changed and they are the basic building blocks for program statements.

 

• Data type is the type of the data, that are going to access within the program. All C compilers supports the five fundamental data types called int, char, float, double and void.

 

• A Variable is an identifier that is used to represent some specified type of information within a designated portion of the program. A variable may take different values at different times during the execution. i.e. it is the named memory location.

 

Type declaration: 'C' Language provides a feature to declare a variable of the type of user defined type declaration. Which allows users to define an identifier that would represents an existing data type and this can later be used to declare variables.

 

Integer Constants: An integer constant formed with the sequence of digits. There are three types of integer constants which forms different number system.

 

• Real Constants: A real constant is made up of a sequence of numeric digits with presence of a decimal point. Real constants serve as a good purpose to represent quantities that vary continuously such as distance, heights, temperatures etc.

 

• String Constants: A string constant is a sequence of characters enclosed in double quotes, the characters may be letters, numbers, special characters and blank spaces etc. At the end of string '\0' is automatically placed.

 

• Statements can be defined as set of declaration, or sequence of action. Statement causes the computer to perform some action. All statements in 'C' language ends with semicolon except conditioned and control structured.

 

• An operator is a symbol that specifies an operation to be performed on the operands. The data items that operators acts upon are called operands.

• Types of operators.

a) Arithmetic operators.

b) Relational operators.

c) Logical operators.

d) Assignment operators.

e) Increment and decrement operators.

f) Bitwise operators.

g) Special operators.

h) Conditional operators (Ternary operator).

 

• Relational operators are used to compare two or more operands. Operands may be variables, constants or expression.

 

• Logical operators are used to combine the results of two or more conditions.

 

• 'C' has two way useful operators not generally found in other languages, these are the increment (++) and decrement (‒) operators.

 

• Conditional operator itself checks the condition and executes the statement depending on the condition.

 

• Bitwise operators are used to manipulate the data at bit level. It operates on integers only. It may not be applied to float or real.

 

• Bitwise AND (&): This operator is represented as '&' and operates on two operands of integer type.

 

• Bitwise OR (|): Similar to AND operator in all aspects, but this operator gives if either of the operand bit is 1' then result is '1' or both operands are 1's then also given '1'.

 

• Bitwise Exclusive OR (^): Similar to AND operator in all aspects but integer gives if either of the operand bit is high(1) then it gives high(1) result. If both operand bits are same then it gives low(0) result.

 

• The sizeof() operator: The sizeof() is a unary operator, that returns the length in bytes of the specified variable, and it is very useful to find the bytes occupied by the specified variable in the memory.

 

• The type conversion or typecasting refers to the process of changing an entity of one data type into another, i.e., You can mix the types of values in your arithmetic expressions.

 

• The implicit type conversion is referred as coercion.

 

• The explicit type conversion is known as casting.

 

• The getchar() function reads a single character from a standard input device. This function do not require any arguments.

 

• The putchar() function is used to display one character at a time on the standard output device.

 

• The getc() function is used to accept a single character from the standard input to a character variable.

 

• The putc() function is used to display a single character in a character variable to standard output device.

 

• The gets() function is used to read the string (string is a group of characters) from the standard input device (keyboard).

 

• The getch() and getche(): The getch reads a single character directly from the keyboard, without echoing to the screen.

 

• Control string: It is the type of data that the user going to accept via the input statements, this can be formatted and always preceded with a "%' sign.

 

• The printf(): Output data or result of an operation can be displayed from the computer to a standard output device using the library function printf().

 

Sequential structure, in which instructions are executed in sequence.

 

Selection structure, here the sequence of the instructions are determined by using the result of the condition.

 

Iteration structure, in which statements are repeatedly executed. These forms program loops.

 

• The if statement is a decision making statement. It is used to control the flow of execution of the statements and also used to test logically whether the condition is true or false.

 

• The if.. else statement is used to execute some statements when the condition is true and execute some other statements, when the condition is false.

 

• When a series of if..else statements are occurred in a program, we can write an entire if..else statement in another if..else statement called nesting. and the statement is called nested if.

 

Nested if statements can become quite complex. If there are more than three alternatives and indentation is not consistent, it may be different for you to determine the logical structure of the if statement. In situations, you can use the nested if as the else if ladder.

 

• The switch statement is used to pickup or executes a particular group of statements from several available group of statements. It allows us to make a decision from the number of choices.

 

• The loop in a program consists two parts, one is body of the loop and another one is control statement. The control statement is used to test the condition and then directs the repeated execution of the statements in the body of the loop.

 

• The while loop is a repetitive control structure, used to execute the statements within the body until the condition becomes false.

 

• The do..while loop: It is also repetitive control structure and executes the body of the loop once irrespective of the condition, then it checks the condition and continues the execution until the condition becomes false.

 

• The for loop is also repetitive control structure, and is used to execute set of instructions repeatedly until the condition becomes false.

 

• The break statement is used to terminate the loop. When the keyword break is used inside any 'C' loop, control automatically transferred to the first statement after the loop.

 

• The continue Statement: In some situations, we want to take the control to the beginning of the loop, bypassing the statements inside the loop which have not yet been executed, for this purpose the continue is used.

 

• A goto statement can cause program control almost anywhere in the program unconditionally. The goto statement requires a label to identify the place to move the execution. A label is a valid variable name and must be ended with colon (:).

 

MULTIPLE CHOICE QUESTIONS

 

1. Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A. rem = 3.14 % 2.1;

B. rem = modf(3.14, 2.1);

C. rem = fmod(3.14, 2.1);

D. Remainder cannot be obtained in floating point division.

 

2. What are the types of linkages?

A. Internal and External

B. External, Internal and None

C. External and None

D. Internal

 

3. Which of the following special symbol allowed in a variable name?

A. * (asterisk)

B. | (pipeline)

C. ‒ (hyphen)

D. _ (underscore)

 

4. Is there any difference between following declarations?

1: extern int fun();

2: int fun();

A. Both are identical

B. No difference, except extern int fun(); is probably in another file

C. int fun(); is overrided with extern int fun();

D. None of these.

 

5. How would you round off a value from 1.66 to 2.0?

A. ceil(1.66)

B. floor(1.66)

C. roundup(1.66)

D. roundto(1.66)

 

6. What are the different types of real data type in C?

A. float, double

B. short int, double, long int

C. float, double, long double

D. double, long int, float

 

7. Which of the following is not logical operator?

A. &

B. &&

C. ||

D. !

 

8. Which of the following cannot be checked in a switch‒case?

A. Character

B. Integer

C. Float

D. enum

 

9. How many times "VRB" is get printed?

int main()

{

    int x;

    for(x=‒1; x <=10; x++)

    {

        if(x < 5)

            continue;

        else

            break;

    printf("VRB");

    }

}

A. Infinite times

B.11 times

C. 0 times

D.10 times

 

10. In mathematics and computer programming, which is the correct order of mathematical operators?

A. Addition, Subtraction, Multiplication, Division

B. Division, Multiplication, Addition, Subtraction

C. Multiplication, Addition, Division, Subtraction

D. Addition, Division, Modulus, Subtraction

 

11. How many times the while loop will get executed if a short int is 2 byte wide?

#include <stdio.h>

int main()

{

    int j=1;

    while(j <= 255)

    {

        printf("%c %d\n", j, j);

        j++;

    }

}

A. Infinite times

B. 255 times

C. 256 times

D. 254 times

 

12. In the following code, the P2 is Integer Pointer or Integer? typedef int *ptr; ptr p1, p2;

A. Integer

B. Integer pointer

C. Error in declaration

D. None of above

 

13. In the following code what is 'P'?

typedef char *charp;

const charp P;

A. P is a constant

B. P is a character constant

C. P is character type

D. None of above

 

14. Which of the following is the correct order of evaluation for the below expression?

z = x + y * z / 4 % 2‒1

A. */% ‒ +

B. =*/% + ‒

C. /* % ‒+ =

D. * %/‒ +=

 

15. Which of the following correctly shows the hierarchy of arithmetic operations in C?

A. / + *_

B. *‒/+

C. + ‒/*

D. /* + ‒

 

16. Which of the following is the correct usage of conditional operators used in C?

A. a>b? c=30: c=40;

B. a>b?c=30;

C. max = a>b? a> c?a:c:b>c?b:c

D. return (a>b)?(a:b)

 

17. Which of the following is the correct order if calling functions in the below code?

a = f1 (23, 14)* f2(12/4) + f3();

A. f1, f2, f3

B. f3, f2, fl

C. Order may vary from compiler to compiler

D. None of above

 

18. Which of the following are unary operators in C?

1. ! 2. Sizeof 3. ~4. &&

A.1, 2

B. 1,3

C. 2,4

D. 1, 2, 3

 

TRUE FALSE

 

1. A float is 4 bytes wide, whereas a double is 8 bytes wide.

True/False

2. Size of short integer and long integer can be verified using the sizeof() operator.

True/False

3. Range of double is ‒1.7e‒38 to 1.7e+38 (in 16 bit platform ‒ Turbo C under DOS)

True/False

4. In a call to printf() function the format specifier %b can be used to print binary equivalent of an integer.

True/False

5. Associativity has no role to play unless the precedence of operator is same.

True/False

6. The expression of the right hand side of || operators doesn't get evaluated if the left hand side determines the outcome.

True/False

7. In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators.

True/False

8. Associativity of an operator is either Left to Right or Right to Left.

True/False

9. The way the break is used to take control out of switch and continue to take control of the beginning of the switch?

True/False

10. Can we use a switch statement to switch on strings?

True/False

11. We want to test whether a value lies in the range 2 to 4 or 5 to 7. Can we do this using a switch?

True/False

12. By default, the data type of a constant without a decimal point is int, whereas the True/False one with a decimal point is a double.

13. Can we specify a variable filed width in a scanf() format string?

True/False

14. Left shifting a number by 1 is always equivalent to multiplying it by 2.

True/False

15. Bitwise & and | are unary operators.

True/False

16. Bitwise & can be used to check if more than one bit in a number is on.

True/False

17. Bitwise & can be used to check if a bit in number is set or not.

True/False

18. Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.

True/False

19. Bitwise can be used to reverse a sign of a number.

True/False

20. Bitwise can be used to generate a random number.

True/False

21. Bitwise | can be used to multiply a number by powers of 2.

True/False

22. Bitwise | can be used to set multiple bits in number.

True/False

23. Associativity has no role to play unless the precedence of operator is same.

True/False

24. Associativity of an operator is either Left to Right or Right to Left.

True/False

25. Two different operators would always have different Associativity.

True/False

26. Will the expression *p = p be disallowed by the compiler?

True/False

27. Every operator has an Associativity.

True/False

 

Computer Programming C: UNIT I: Introduction to C : Tag: Computer Science : Computer Programming C - Introduction to C: 2 marks Definitions Answers


Computer Programming C: UNIT I: Introduction to C



Under Subject


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation