0% found this document useful (0 votes)
5 views6 pages

Unit II

Uploaded by

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

Unit II

Uploaded by

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

Answers to PIC (Unit 2) Questions

1. Define Type Casting: Type casting is the process of


converting a variable from one data type to another.
Example:
float x = 9.8;
int y = (int)x; // y becomes 9

2. Functions Explanation:

 getchar(): Reads a single character from standard input.


 putchar(): Writes a single character to standard output.
 getch(): Reads a single character without displaying it on
the screen.
 putch(): Displays a single character on the console.

3. Use of printf() and scanf() with Examples:

 printf():Displays formatted output.


 scanf(): Reads formatted input. Example:

int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d\n", num);

4. Formatted Input with Examples:


int a;
float b;
printf("Enter an integer and a float: ");
scanf("%d %f", &a, &b);
printf("You entered: %d and %.2f\n", a, b);

5. Logical AND Operator Program:


#include <stdio.h>
#include <conio.h>
void main() {
int x = 1, y = 0;
clrscr();
if (x && y) {
printf("Both are true");
} else {
printf("At least one is false");
}
getch();
}

6. Increment and Decrement Operator:

 Increment (++) and Decrement (--) Examples:


int x = 5;
printf("%d\n", ++x); // Pre-increment
printf("%d\n", x--); // Post-decrement

7. User-defined Function:
#include <stdio.h>
#include <conio.h>

void greet() {
printf("Hello, User!\n");
}

void main() {
clrscr();
greet();
getch();
}

8. Conditional Operator:
int a = 5, b = 10;
int max = (a > b) ? a : b;
printf("Max: %d\n", max);

9. Four Keywords in C:
 int: Declares integer variables.
 float: Declares floating-point variables.
 if: Conditional statement.
 return: Returns a value from a function.

10. Bitwise Operators:

 &: AND
 |: OR
 ^: XOR
 ~: NOT
Example:
int a = 5, b = 3;
printf("%d\n", a & b);

11. Generic Structure of C Program:


#include <stdio.h>

void main() {
printf("Hello World\n");
}

12. Format Specifiers:

 %d: Integer
 %f: Float
 %c: Character
 %s: String
Example:
int x = 10;
printf("Value: %d\n", x);

13. Arithmetic and Logical Operators:


 Arithmetic: +, -, *, /, %
 Logical: &&, ||, !
Example:
printf("%d\n", 10 + 5);
printf("%d\n", (1 && 0));

14. Formatted Input/Output Statements:


int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d\n", num);

15. Special Operators:

 sizeof():
Returns the size of a data type
 ,: Comma operator
 *: Pointer operator
 .: Member access operator
Example:
int x = 5;
printf("Size: %d\n", sizeof(x));

16. Definitions:

 Identifier: Name for variables, functions, etc.


 Token: Smallest element in a program.

17. Operator Precedence and Associativity:


Precedence determines operation order; associativity
resolves ties (left-to-right or right-to-left).

18. Four Types of C Language:


 Procedural
 Structured
 Modular
 Functional

19. Relational Operators:

 ==: Equal
 !=: Not equal
 <: Less than
 >=: Greater than or equal
Example:
int a = 5, b = 10;
printf("%d\n", a < b); // Outputs 1

20. Descriptions:

 Keyword: Reserved word, e.g., if


 Identifier: Name for variable, function
 Variable: Data storage
 Constant: Fixed value

21. Short Notes:

 Escape Sequence Characters: \n, \t


 Conversion Specification Characters: %d, %f

22. Difference Between gets() and getchar():

 gets():Reads an entire string.


 getchar(): Reads a single character.
23. Purpose of scanf(): Reads formatted input from the
user.

24. Output of Given Program: Corrected Output:


value of v1:10
value of v2:11

25. Data Types in C:

 int: 2 or 4 bytes
 float: 4 bytes
 char: 1 byte
 double: 8 bytes

You might also like