1. What are the different data types available in "C"?
• C supports three classes of data types:
o Basic / Primary / Build-in data types
o Derived data types
? Array, pointer,
? Structure union and
o User-defined data types
2. What is an Operator, Operand and Keywords?
• 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. Example: a+b; In this statement a and b are called operands.
• 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.
• These fixed values are also called literals.
• The constants are treated just like regular variables except that their values cannot be modified after their definition.
• For example: 1, 2.5, "Programming is easy." etc.
• Types of constants are
4. i) What is Ternary operators or Conditional operators?
i) Ternary operators or Conditional operators
• Conditional operator itself checks the condition and executes the statement depending on the condition.
• It is also called as ternary operator.
Condition ? exp1:exp2;
• The '?' operator acts as a ternary operator.
• Ternary operator works as follows,
? First, the conditions will be evaluated.
? if the condition is true exp1 is evaluated,
? if the condition is false exp2 is evaluated.
• Conditional operator works like if-else statement.
x = (a>b) ? a:b;
ii) Example for Ternary operator
/* Program for conditional Operator */
printf("x is %d", x);
Output: x is 5
5.What are the Bitwise operators and logical operators available in C ?
& Bitwise AND
| Bitwise OR
~ One's complement
^ Bitwise XOR
<< Left shift
>> Right shift
&& Logical AND
|| Logical OR
! Logical NOT
6. What is a Variable? Illustrate it with an example.
• The value of the variable can be changed during the execution of a program.
• C variable might be belonging to any of the data type like int, float, char etc.
• Each variable should be given a unique name called identifier.
• Variable name must begin with letter or underscore.
Sum, average, etc
7. What is the difference between Logical AND and Bitwise AND?
• Logical AND (&&): Only used in conjunction with two expressions, to test more 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.
8. (i)What is the difference between "=" and "= =" operator?
• Where = is an assignment operator and == is a relational operator.
• Example: i=5 ?assigns value 5 to variable i, if(i==5)?checks variable i equal to 5 or not
(ii)What is the difference between 'a' and "a"?
'a' is a character constant and "a" is a string.
9. 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.
10. What are various types of C operators?
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment & decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
11. What are the main features and applications of C language?
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.
12. What is the difference between while loop and do…while loop? (or) Differentiate Entry and Exit controlled constructs.
Its an entry controlled loop Its an exit controlled 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
//body of the loop
//body of the loop
13. What is a Modulo Operator? What is the use of sizeof( ) operator?
• '%' is modulo operator. It gives the remainder of an integer division.
• Example: a=17, b=6. Then c=%b gives 5.
Sizeof( ) operator
• The sizeof ( ) operator gives the bytes occupied by a variable.
• No of bytes occupied varies from variable to variable depending upon its data types.
o Output: 2
14. Define with example integer and floating type of data in C language.
• 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)
o 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 numbers are denoted by the keyword float.
o Example: float miles = 4.5
15. 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)
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*/
16. What are the types of I/O statements available in C?
17. 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
• Example program
int a, b, sum;
printf("\nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
Enter two no: 5 6
Sum : 11
18. 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.
int a,b; //a,b are global variables
19. Construct an infinite loop using while?
Here 1 is a non zero value, so the condition is always true. So it is an infinite loop.
20. What are the Escape Sequences present in "C"
Escape Sequence Symbol Escape Sequence Name
\n New Line
\t Tab space
\r Carriage return
\f Form feed
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
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 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.Write a for loop statement to print numbers from 10 to 1.
for( i=10; i>=1; i--)
10 9 8 7 6 5 4 3 2 1
24.Write a C Program to find factorial of a given number using iteration.
printf("Enter a number: ");
printf("Factorial of %d is: %d",num,f);
Enter a number: 5 Factorial of 5 is 120
25.Define Compilation, linking process?
• 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.
26. Define with example integer and floating type of data in C language.
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). . Floating point numbers are denoted by the int float.
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 numbers are denoted by the keyword float.
miles = 4.5
27. . What are the main features and applications of C language?
C programming language that was capable of both high level, machine independent
programming and would still allow the programmer to control the behavior of individual bits of information. C includes bitwise operators along with powerful pointer manipulation capabilities.
28. 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.
29.What is the importance of keywords in 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.
30.List the various input and output statements in C?
Input : In any programming language input means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement.
Output : In any programming language output means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output required data.