Important Questions in CF&P-1
Important Questions in CF&P-1
Explain High level Language, Low Level Languge, Assembly Level Language.
1. Source Code:
Source code refers to high level code or assembly code which is generated by
human/programmer. Source code is easy to read and modify. It is written by programmer
by using any High Level Language or Intermediate language which is human-readable.
Source code contains comments that programmer puts for better understanding.
2. Object Code:
Object code refers to low level code which is understandable by machine. Object code is
generated from source code after going through compiler or other translator. It is in
executable machine code format. Object code contains a sequence of machine
understandable instructions to which Central Processing Unit understands and executes.
5. Object file contains object code. It is considered as one more of machine code. Some
object file examples are common object file format (COFF), COM files and “.exe” files.
It is the output of a compiler or other translator. We can understand source code but we
can not understand object code as it is not in plain text like source code rather it is in
binary formats.
Difference between Source Code and Object Code :
S.
SOURCE CODE OBJECT CODE
No.
Source code is generated by human or Object code is generated by compiler or other
01.
programmer. translator.
02. Source code is high level code. Object code is low level code.
Source code is written in plain text by using Object code is translated code of source code.
03.
some high level programming language. It is in binary format.
04. Source code is human understandable. Object code is not human understandable.
Source code is not directly understandable by
05. Object code is machine
machine.
It is written in a high-level language like C,
It is written in machine language through
06. C++, Java, Python, etc., or assembly
compiler or assembler or other translator.
language.
07. It can be easily modified. It can not be modified.
It contains comments for better understanding It does not contain comments for
08.
by programmer. understanding by machine.
S.
SOURCE CODE OBJECT CODE
No.
It contains less number of statements than It contains more number of statements than
09.
object code. source code.
10. It is less close. towards machine. It is more close towards machine.
Performance of source code is less than Performance of object code is more than
11. object code as it is less close towards source code as it is more close towards
machine. machine.
Source code is input to compiler or any other Object code is output of compiler or any
12.
translator. other translator.
13. Source code is not system specific. Object code is system specific.
6. What do you mean by primitive data types in C, how it differs from derived data types
used in C.?
The data types in C can be classified as follows:
Types Description
Primitive Data Primitive data types are the most basic data types that are used for
Types representing simple values such as integers, float, characters, etc.
User Defined
The user-defined data types are defined by the user himself.
Data Types
The data types that are derived from the primitive or built-in datatypes are
Derived Types
referred to as Derived Data Types.
7. Draw a flowchart to find largest among four numbers.
8. Write short notes on 1)pseduocode 2)Algorithm
9. How to declare idetifers.write scope and lifetime of variable.
Example:
int num = 3
Here,
There are rules for defining the variables in C Programming, and those rules are as follows:
Variable names will always start with an alphabet and underscore. Example: num, name,
a, x, _value.
Variable names in C will never start with a digit. Example: 4name, is an invalid name.
Variables should be declared with their data type. Variable names without data type will
generate errors. For example, int a =2 is valid. a = 2 is an invalid variable.
C is a strongly typed language, you cannot change the data type of a variable after its
definition.
Reserved keywords cannot be used as a variable name in C programming.
No white spaces are allowed within the variable name.
Global scope is the entire program. Global variables can be used anywhere throughout the
program.
Lifetime is the life or alive state of a variable in the memory. It is the time for which a variable
can hold its memory. The lifetime of a variable is static and automatic. The static lifetime
variable remains active till the end of the program.
An automatic lifetime variable or global variable activates when they are called else they vanish
when the function executes.
Types of Variables on the Basis of Scope
The variable that is declared in a function or code is called a local variable. The scope of Local
variables is within the defined function only. You cannot use a local variable outside the function
(in which it is declared).
#include <stdio.h>
void person()
{
// Local Variables of the function
int age = 20;
float height = 5.6;
int main()
{
person();
return 0;
}
Copy code
OUTPUT
age is 20
height is 5.600000
Global Variables
The scope of the global variable is the entire program. They are not defined inside any function
and can be used in any function.
#include <stdio.h>
void function1()
{
// Function using global variable a
printf("The number is %d \n", a);
}
void function2()
{
// Function using global variable a
printf("The number is %d \n", a);
}
int main()
{
// Calling functions
function1();
function2();
return 0;
}
Copy code
OUTPUT
The number is 23
The number is 23
UNIT 3
1. Explain the Concept of while loop in C with example.
2. WAP in to print following pattern
ABCDE
ABCD
ABC
AB
A
UNIT 4
OR
1) Call by Value
struct car {
char name[30];
int price;
};
void print_car_info(struct car c)
{
printf("Name : %s", c.name);
printf("\nPrice : %d\n", c.price);
}
int main()
{
struct car c = { "Tata", 1021 };
print_car_info(c);
return 0;
}
1) Call by References
struct car {
char name[30];
int price;
};
void print_car_info(struct car *c)
{
printf("Name : %s", c->name);
printf("\nPrice : %d\n", c->price);
}
int main()
{
struct car c = { "Tata", 1021 };
print_car_info(&c);
return 0;
}
struct date{
int day;
int mon;
int yr;
};
main ( ){
struct date d= {02,01,2010}; // struct date d;
display(d.day, d.mon, d.yr);// passing individual mem as argument to
function
getch ( );
}
display(int a, int b, int c){
printf("day = %d
", a);
printf("month = %d
",b);
printf("year = %d
",c);
}
int main()
{
int arr[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
func(arr);
return 0;
}
int main()
{
int arr[][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print(arr);
return 0;
}
OR
#include <stdio.h>
int main()
{
char array[100];
int i,n;
scanf(“%d”,&n);
for (i=0;i<=n-1;i++)
{
scanf("%c", array[i]);
For(i=0;array[i]!=’\0’;i++)
return 0;
}
7.WAP to copy one string into another string.
1)fseek()
2)fread()
3)fwite()
4)fputc()
5)fgetc()