0% found this document useful (0 votes)
8 views15 pages

2 Marks

The document provides an overview of C programming, including the structure of a C program, variable declaration rules, data types, operators, control statements, functions, arrays, pointers, structures, and file handling. It also covers the differences between various programming constructs, such as loops and conditionals, and explains concepts like recursion and user-defined functions. Additionally, it discusses command line arguments and the types of files in C programming.
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)
8 views15 pages

2 Marks

The document provides an overview of C programming, including the structure of a C program, variable declaration rules, data types, operators, control statements, functions, arrays, pointers, structures, and file handling. It also covers the differences between various programming constructs, such as loops and conditionals, and explains concepts like recursion and user-defined functions. Additionally, it discusses command line arguments and the types of files in C programming.
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

1. Draw the structure of a C program.

The Structure of a C program is given below:

Include Header file Section

Global Declaration Section

/* Comments */

main()
{
/* Comments */

Declaration part;
Executable part;

User-defined functions
{
statements;
}

2. Write a C program to determine whether a number is ‘odd’ or ‘even’ and


print the message.
#include<stdio.h>
#include<conio.h>
void main()
{
int num , rem;
clrscr();
printf(“enter the number”);
scanf(“%d”,&num);
rem=num%2;
if(rem==0)
printf(“the number is even”);

1
else
printf(“thenumber is odd”);
getch();}

3. List the rules that are to be followed while declaring variables.


Rules for naming the variables:

i. A variable name can be any combination of 1 to 8 alphabets, digits or


underscore.
ii. The first character must be an alphabet or an underscore.
iii. The length of the variable cannot exceed upto 8 characters long.
iv. No commas or blank spaces are allowed within a variable name.
v. No special symbol, an underscore can be used in a variable name.

[Link] the meanings of the following keywords in C: double, int, long. (Apr/May
2008)
Data type Description Memory Bytes Control String
int Integer Quantity 2 Bytes %d or %i
Char Single Character 1 Byte %c
Float Floating point no. 4 Bytes %f
Double Double precision 8 Bytes %lf
floating point nos.

5. What is the main advantage of conditional operator? Give the syntax of


conditional operators in C.
Conditional Operator: It checks the condition and executes the statements depending on
the condition.
Syntax: condition?exp1:exp2
The ? operator acts as a ternary operator. If the condition is true, it evaluate the first
expression otherwise it evaluates the second expression.

2
6. What is the use of break statement in switch statement?
The break statement is used to terminate the loop. The keyword is break.
When the break statement is encountered inside a loop, the loop immediately exited .

Syntax;
break;

7. What is the use of bitwise operators in C? Give any one bitwise operator with its
meaning
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ One’s Complement
>> Right Shift
<< Left Shift

8. List the logical operators


It is used to combine the results of two or more conditions.
Operator Meaning Example Return Value (Result)
&& Logical AND (4<6)&&(8==9) 0
|| Logical OR (7<9)||(3<1) 1
! Logical NOT !(29>89) 1

9. Write the steps involved in executing a C program

1. Creation of program.
2. Compilation and linking of a program.
3. Executing the program.

3
10. What are the different types of C tokens

The tokens are usually referred as individual text and punctuation in a passage of text.
The C language program contain individual units called the C tokens and has the
following types.

C Tokens

Identifiers Keywords Constants Strings Operators Special


Eg. int Eg: 48 Eg: Symbols
Eg: main() double 78.90 “xyx” Eg: +, -,*
total for “hi” Eg. #, &,

11. What are the different types of operators?


There are different types of operators. They are:
1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Assignment Operator
5. Increment & decrement Operator
6. Conditional Operator
7. Bitwise Operator
8. Special Operator

4
12. What are the different functions used in input and output operations?
1. Formatted Input/Output Functions
2. Unformatted Input/Output Functions

Input & Output Functions

Unformatted Formatted

Input Output Input Output

getc() putc() scanf() printf()


getchar() putchar() fscanf() fprintf()
gets() puts()

13. Write the difference between while and do. while loops.
While.. do do.. while

1. this is top tested loop This is bottom tested loop.

[Link] condition is first tested, It execute the body once, after


If condition is true then the check the condition. Block is executed
until the Condition become false until the Condition become false

[Link] will not be executed if Loop is executed at least once, even


The condition is false though the condition is false

14. What are the features of ‘for’ loop?


1. Initialize: is used foe initializing counter variable.
2. Test condition: used for test the condition.
3. increment/decrement: used for increment/decrement the counter variable.
Features:
1. Reduce the instruction of the statement.
2. Execution of the time is reduced.

5
15. What is meant by global declaration?
The variables that are used in more than one function throughout the program are
called global variables and declared outside of all the function i.e. before main ()

16. Define logical and data errors.


Logical error: These are errors in which the conditional and control
statements cannot end their match after some sequential execution
Data error: These are errors in which the input data is not in proper syntax
as specified in the input statements

17. List out the characteristics of a program.


a) Clarity
b) Integrity
c) Simplicity
d) Efficiency
e) Generality

18. What is conversion specification?


The conversion specification are used to accept or display the data using the
INPUT/OUTPUT statements

19. What is meant by switch statement?


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

20. What is the difference between if and while statement?

If While
a) It is conditional statement a) It is a loop control
statement
b) If the condition is true, it b) Executes the statements
executes some statements within the while block if
the condition is true
c) It the condition is false, it c) If the condition is false,
stops the execution of the the control is transferred to
statements the next statement of the
block

6
21. What is a Data type?

Data types simply refers to the type and size of data associated
with variables and functions.

Data types in C

1. Fundamental Data Types


o Integer types
o Floating type
o Character type
2. Derived Data Types
o Arrays
o Pointers
o Structures
o Enumeration

22. What is a constant?


Constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called [Link] can be of any of
the basic data types like an integer constant, a floating constant, a
characterconstant, or a string literal.

23. Define function. What are the different types of function?


A function is a set of instruction that are used to perform specified task which
repeatedly occurs in main program. The different types of functions are:
1. User-defined functions
2. Pre-defined Function.

24. What is Recursion?


Recursion is the process by which a function call itself repeatedly.

7
25. What are the different types of function parameters?
The different types of function parameters are:
1. Actual parameters
2. Formal parameters

26. What is function prototype?


A function prototype is a function declaration before the main program. This is done
to inform the compiler that there is a user defined function in the program.

27. What are the different types of function prototypes?


There are four different types of function prototypes. They are:
i. Function with no arguments and no return values
ii. Function with arguments and no return values
iii. Function with arguments and with return values
iv. Function with no arguments and with return values

28. What are the different parameter passing methods?


There are two methods for passing the parameter. They are:
i. Call by value.
ii. Call by reference.
29. What is the purpose of return statement?
The return statement returns the value or control to the calling function.

30. What is user-defined function? State its advantages.


A user-defined function is a function which is defined by the user.
Advantage of User-defined function
1. The length of source program can be reduced by dividing it into smaller function.
2. Easy to locate and debug error.
3. function avoid coding of repeated programming of the similar instructions.

8
31. What are the elements of user-defined functions?
The Elements of user –defined function
1. function definition.
2. function declaration .
3. Function call

[Link] is an array? Give the general form of array declaration.


An array is a collection of similar data item, that are stored under a common name,
The value in an array is identified by index, subscript enclosed by square brackets
with array name.
Declaration:
int a[10];
Where int is the data type of the array; a is the array name; 10 is the size of the array.
Array can be classified into
1. ONE-Dimensional array.
2. TWO- Dimensional array.
3. Three- Dimensional array.

33. Write the features of array.


▪ Array contains similar data elements.
▪ Array stores fixed number of data elements.
▪ The elements in the array can be accessed by the index of the array.
▪ The elements are stored in contiguous location in an array

34. What is a pointer? List out any two uses of pointers.


A pointer is a variable which stores the address of the variable.

Example:
int a, *j;
j=&a;
j contains the address of a.

9
Uses:
i. The data can be manipulated with the help of its address.
ii. The value of the data need not be known for its manipulation.
iii. Dynamic memory allocation can be done.

[Link] a C program to print the address of a variable using pointer.


#include <stdio.h>
void main()
{
int a,*x;
clrscr();
a=20;
x=&a;
printf("\nThe value of a =%d",a);
printf("\nThe address of a =%u",x);
getch();
}
[Link] an example program in C to access a variable through its pointer.
#include <stdio.h>
void main()
{
int a,*x;
clrscr();
a=20;
x=&a;
printf("\nThe value of a =%d",a);
printf("\nThe address of a =%u",x);
printf(“\nThe value of a = %d”,*x);
getch();
}

10
[Link] the advantages of using pointers.
• Pointers save the memory space.
• Execution time with pointer is faster because data is manipulated with the
address.
• The memory is accessed efficiently with the pointers.
• Dynamically, memory is allocated.
• Pointers are useful for representing two-dimensional and multi-
dimensional arrays.

[Link] are the operators exclusively used with pointers?


* (asrerisk) & & (ambersand) are the operators exclusively used with pointers.

[Link] Null pointer.


A Pointer variable which does not contain anything is called as Null Pointer.

[Link] the syntax of pointer declaration.


int a, *j;
j=&a;

[Link] is structure? Write the syntax of structure declaration.


A Structure is a collection of one or more variables of different data types, grouped
together under a single name. By using structures, we can make a group of variables,
arrays, pointers etc.

Declaration & Initialization of Structures:


Structures can be declared as follows:
struct struct_name
{
datatype variable1;
datatype variable2;
};
struct struct_name variable1,variable2;

11
[Link] is the purpose of union in C programming?
Memory allocation is done for the data member which requires maximum allocations.
Hence Less memory space is needed. Hence Union is used in C Programming.

[Link] structures with unions


[Link] Structure Union
1. The keyword is struct. The keyword is union.
2. Memory allocation is done for all Memory allocation is done for the data
the data members in the member which requires maximum
structures. allocations.
Example. Example:
struct student union student
{ {
int rollno; int rollno;
char name[5]; char name[5];
}s1; }
The memory allocation is 7 Bytes. The memory allocation is 5 Bytes
3. All the data members are Only the last stored data element is
available in the primary memory available in the primary memory at
at any time of execution. any time of execution.
4. Since memory is allocated for all Since memory is not allocated for all
the data members, no data is the data member, only one data is
deleted in the primary memory available and other data is deleted
from the primary memory

12
[Link] is a nested structure?
A structure with in a structure is called a nested structure.

[Link] is meant by self referential structure?


A Structure which references itself is called a self-referential structure.
Example:
Struct stack
{
int data;
struct stack *next;
} *top=NULL;

46. What is meant by pre processor?


The preprocessor is a program that processes the source program before it is passed
on to the compile. Any preprocessor directive starts with #.

.
[Link] is file?
A file represents a sequence of bytes on the disk where a group of related data is
stored. File is created for permanent storage of data. It is a readymade structure.

A file represents a sequence of bytes, regardless of it being a text file or a binary file. C
programming language provides access on high level functions as well as low level (OS
level) calls to handle file on your storage devices. This chapter will take you through the
important calls for file management.

48. What is Sequential access files

Sequential files are generally used in cases where the program processes the data in a
sequential fashion – i.e. counting words in a text file – although in some cases, random
access can be feigned by moving backwards and forwards over a sequential file.

49. What are random access files?

random access file handling, however, only accesses the file at the point at which the
data should be read or written, rather than having to process it sequentially. A hybrid

13
approach is also possible whereby a part of the file is used for sequential access to locate
something in the random access portion of the file, in much the same way that a File
Allocation Table (FAT) works.

[Link] are the three main function?

The three main functions are:

• rewind() – return the file pointer to the beginning;

• fseek() – position the file pointer;

• ftell() – return the current offset of the file pointer.

Each of these functions operates on the C file pointer, which is just the offset from the
start of the file, and can be positioned at will. All read/write operations take place at the
current position of the file pointer.

[Link] is command line arguments?

It is the number of arguments passed into the program from the command line,
including the name of the program. The array of character pointers is the listing of all
the arguments. argv[0] is the name of the program, or an empty string if the name is not
available.
[Link] are the Types of Files?

When dealing with files, there are two types of files you should know about:

1. Text files
2. Binary files

53. What is meant Text files?

Text files are the normal .txt files that you can easily create using Notepad or any simple
text editors.

When you open those files, you'll see all the contents within the file as plain text. You
can easily edit or delete the contents.

14
They take minimum effort to maintain, are easily readable, and provide least security and
takes bigger storage space.

54. What is meant Binary files?

Binary files are mostly the .bin files in your computer.

Instead of storing data in plain text, they store it in the binary form (0's and 1's).

They can hold higher amount of data, are not readable easily and provides a better
security than text files.

15

You might also like