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

Answers C

Uploaded by

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

Answers C

Uploaded by

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

1. What are keywords give an example.

Keywords are words that have special meaning to the C compiler.

The C language uses the following keywords:

Auto Break case char

const continue default do

double else enum extern

float for goto if int long register

return short signed sizeof static

2.List different data types available in C.

Data types are used to specify the type of a variable.

In c, the data types are classified into 3 category.

They are, Primary or Built-in : int , char, float

Derived : array, enum, pointer

User defined : function, structure

3.Define operators.

An operator is a symbol that is to perform mathematical or logical manipulation. It is used


in program to manipulate data and variables

4.Define decision making statement.

These statements are used to execute particular set of instruction for based on certain
condition.

Ex:if, if else, nested if, if else if ladder, switch.

5.Define looping statement.

Looping statement are used to execute a group of instruction repeatedly at till some
condition is satisfied.

Example: while, do while, for loop.

6. Define unconditional statement.

This condition is used to transfer the control to other statement without checking any
condition. Example : goto, break
7. 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.

8. What is the difference between while loop and do…while 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 do…while loop first the statement is
executed and then the condition is checked. The do…while loop will execute at least one time even
though the condition is false at the very first time.

9. Write the limitations of getchar( ) and sacnf( ) functions for reading strings
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.

10. What are the Bitwise operators available in ‘C’?


& - 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.

11.Generalize the types of I/O statements in C language.


getchar() This function is an Input function.
putchar() This function is an output function.
gets() This function is an input function.
puts() This is an output function.
getch() This is also an input function.
scanf()
printf()

12.Identify the use of ternary operator.


The programmers utilize the ternary operator in case of decision making when
longer conditional statements like if and else exist. In simpler words, when we use an
operator on three variables or operands, it is known as a Ternary Operator. We can
represent it using ? : . Thus, it is also known as a conditional operator.

13.What is compilation process?

The compilation process in C is converting an understandable human code into a


Machine understandable code and checking the syntax and semantics of the code to
determine any syntax errors or warnings present in our C program. Suppose we want to
execute our C Program written in an IDE (Integrated Development Environment). In that
case, it has to go through several phases of compilation (translation) to become an
executable file that a machine can understand.

14.How does a preprocessor work?


The preprocessor provides inclusion of header files, macro expansions, conditional
compilation, and line control. In many C implementations, it is a separate program invoked
by the compiler as the first part of translation.

Part – B(1*15=15)
6.(i)Describe the structure of a C program with an example (8)

The structure of a C program can be mainly divided into six parts, each having its purpose. It
makes the program easy to read, easy to modify, easy to document, and makes it consistent in
format.

Basic Structure of the C Program


Section Description
Consists of the description of the program, programmer's name, and creation date.
Documentation These are generally written in the form of comments.

All header files are included in this section which contains different functions
from the libraries. A copy of these header files is inserted into your code before
Link
compilation.

Includes preprocessor directive, which contains symbolic constants.


E.g.: #define allows us to use constants in our code. It replaces all the constants
Definition
with its value in the code.

Includes declaration of global variables, function declarations, static global


Global
variables, and functions.
Declaration
For every C program, the execution starts from the main() function. It is
Main() Function mandatory to include a main() function in every C program.

Includes all user-defined functions (functions the user provides). They can contain
Subprograms the inbuilt functions and the function definitions declared in the Global
Declaration section. These are called in the main() function.
Example: Write a program to calculate our age.

In the following example, we'll calculate age concerning a year.

Algorithm

You've to subtract the current year from your birth year and get your age.

Code:

/** //Documentation

* file: age.c

* author: you

* description: program to find our age.

*/#include <stdio.h> //Link

#define BORN 2000 //Definition

int age(int current); //Global Declaration

int main(void) //Main() Function

int current = 2021;

printf("Age: %d", age(current));

return 0;

int age(int current) { //Subprograms

return current - BORN;

}
(ii)Write a c program to find the given number is odd or even using switch statement.

/**
* C program to check Even or Odd number using switch case
*/

#include <stdio.h>

int main()
{
int num;

/* Input a number from user */


printf("Enter any number to check even or odd: ");
scanf("%d", &num);

switch(num % 2)
{
/* If n%2 == 0 */
case 0:
printf("Number is Even");
break;

/* Else if n%2 == 1 */
case 1:
printf("Number is Odd");
break;
}

return 0;
}

Output:

Enter any number to check even or odd: 6


Number is Even

You might also like