c Language
c Language
C is a mid-level programming language, also known as the structured programming language. It divides large
programs into smaller modules, where each module employs structured code.
6. What is an array?
A collection of similar-type components is known as an array. It has an uninterrupted memory space. It
optimizes the code and makes it simple to sort and navigate through.
7. What is a token?
The individual elements of a program are called tokens. The following 6 types of tokens are available in C:
Identifiers
Keywords
Constants
Operators
Special Characters
Strings
Function_Body;
The term “i-value” describes a memory address used to identify an object. Either the left or right side of the
assignment operator (=) contains the i-value. In many cases, i-value is used as an identification.
#include <stdio.h>
struct employee {
char name[10];
int age;
} e1;
int main() {
printf("Enter the name: ");
scanf("%s", e1.name);
printf("\n");
scanf("%d", &e1.age);
printf("\n");
return 0;
The output of the code will depend on the values you input during runtime. For example, if you enter name as
John and age as 25, the result will be as follows:
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
c = 'a';
c = 'B';
return 0;
a after conversion: A
B after conversion: B
The toupper() function does not modify the characters that are not in lowercase. So ‘B’ remains ‘B’ and only ‘a’
changes to ‘A’.
#include <stdio.h>
#include <stdlib.h>
int main() {
int* ptr;
int n, i, sum = 0;
n = 5;
if (ptr == NULL) {
printf("Memory not allocated.\n");
exit(0);
} else {
ptr[i] = i + 1;
printf("\n");
return 0;
//Output
33. What is the difference between declaring a header file with < > and
” “?
The compiler looks for the header file in the built-in path if the header file is defined using <>. If the header file
is specified with the character ” “, the compiler will first look in the current working directory for the file before
moving on to other locations if it cannot be found.
35. Write a program to swap two numbers without using the third
variable.
Here is a program to swap two numbers without using the third variable:
#include <stdio.h>
#include <conio.h>
int main() {
clrscr();
a = a + b;
b = a - b;
a = a - b;
getch();
return 0;
Output:
Before swapping a=10 b=20
36. Which structure is used to link the program and the operating
system?
The operating system and the program are joined by the file structure. The file is defined by the “stdio.h” header
file (standard input/output header file). It includes details about the file, including its size and placement in
memory. It also includes a character pointer that directs the user to the currently opened character. When a file is
opened, the connection is made between the program and the operating system.
A 32-bit pointer is regarded as a far pointer. It can make use of the current segment to access data kept outside
of the computer’s memory.
Entry-Controlled Loops: Here, the test condition is checked before entering the main body of the
loop. Examples: For and While loops.
Exit-Controlled Loops: Here, the test condition is checked at the end of the loop body. Example:
do-while loop.
39. What is the difference between source code and object code?
Some of the key differences between source code and object code are:
It can be easily
modified. It cannot be modified.
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &a[i]);
if (a[i] == b[j])
break;
if (j == calc) {
b[calc] = a[i];
calc++;
}
}
return 0;
Enter 8 integers: 1 2 3 4 2 3 5 6
#include <stdio.h>
int main() {
scanf("%d", &array[i]);
swap = array[j];
array[j + 1] = swap;
printf("Sorted Array:\n");
printf("%d\n", array[i]);
}
return 0;
The output of the code depends on the values you put during runtime. Here is what the output can look like:
Enter 5 Numbers:
83512
Sorted Array:
#include<stdio.h>
int abc ()
return 0;
Hello World
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if (j != 0 && j != 1) {
break;
if (num == 0) {
return 0;
The output of this program will vary depending on the number you enter. For example, if you enter the number
1010, the output will be:
#include<stdio.h>
#include<conio.h>
int sumOfDigits(int num, int sum) {
int rem;
if (rem > 0) {
return sum;
int main() {
int num;
scanf("%d", &num);
getch();
return 0;
The output will depend on the number you input during runtime. For example, if you enter the number ‘123’,
the output will be:
It is preprocessed. It is compiled.
Execution is
comparatively
Execution is faster. slower.
DDS can allocate or deallocate the unused memory according to the requirement. Dynamic memory allocation
can be done on both stack and heap as opposed to the static memory allocation, which is done only on the stack.
Examples of dynamic data structures are queues, linked lists, stacks, and trees.
51. Write a program to write two numbers without using the addition
operator.
Here is a program to add two numbers without using the addition operator:
#include<stdio.h>
#include<stdlib.h>
int main()
int x, y;
// method 1
printf("%d\n", x-(-y));
// method 2
printf("%d\n", -(-x-y));
// method 3
printf("%d\n", abs(-x-y));
// method 4
printf("%d", x-(~y)-1);
return 0;
If we enter values ‘5’ and ‘7’, the output of the above program will be:
Method 1: 12
Method 2: 12
Method 3: 12
Method 4: 12
int fib(int n) {
if (n <= 1) {
return n;
int a = 0, b = 1, temp;
temp = a + b;
a = b;
b = temp;
return b;
int main() {
int n = 8;
The output indicates that the 8th Fibonacci number is 21. It is based on the Fibonacci sequence F(n) = F(n-1) +
F(n-2) with base values F(0) = 0 and F(1) = 1.