C PROGRAMMING
calloc() is a dynamic memory allocation function that loads all the assigned memory locations with 0 value.
When a header file in c++ is included in double-quotes, the particular header file is f irst searched in the compiler’s current working directory. If not found, then the built-in include path is also searched.
It is a header file in C that contains prototypes of functions such as scanf and printf.
When we want to restrict access to functions, we need to make them static. Making functions static allows us to reuse the same function in C programming name in multiple files.
Basic data types – Arithmetic data types, further divided into integer and floating-point types
Derived datatypes –Arithmetic data types that define variables and assign discrete integer values only
Void data types – no value is available
Enumerated data types –Array types, pointer types, function, structure and union types
s++ is a single machine instruction used to increment the value of s by 1. (Post increment). ++s is used to carry out pre-increment.
The ‘==’ symbol or “equivalent to” or “equal to” symbol is a relational operator, i.e., it is used to compare two values or variables.
#include <stdio.h>
void local_static()
{
static int a;
printf(“%d “, a);
a= a + 1;
}
int main()
{
local_static();
local_static();
return 0;
}
Answer:
0 1
Some of the feature are:
Middle-Level Language – Combined form of both high level language and assembly language
Pointers – Supports pointers
Extensible – Easy to add features to already written program
Recursion – Supports recursion making programs faster
Structured Language – It is a procedural and general purpose language.
The conditional operator (?:)
As int is a part of standard C language library, and it is not possible to use it for any other activity except its intended functionality, it is known as a reserved word.
void display(unsigned int n)
{
if(n > 0)
{
display(n-1);
printf(“%d “, n);
}
}
Answer:
Prints number from 1 to n.
When a variable’s value is sent as a parameter to a function, it is known as call by reference. The process can alter the value of the variable within the function.
The following information is given while declaring a prototype function:
- Name of the function
- Parameters list of the function
- Return type of the function.[6]
This is because, at any time, the values of the objects can be changed by code outside the scope of the current code.
a=0;
while (a<=10)
{
printf (“%d\n”, a * a);
a++;
}
Answer:
for (a=0; a<=10; a++)
printf (“%d\n”, a * a);
It is used as a prefix to primary data type to indicate the storage space allocation’s modification to a variable. The available modifiers are:
- short
- long
- long long
- signed
- unsigned
Pointers is a concept available in C and C++. The variable ‘v’ might contain the address of another memory or a value.
The number of bytes to search, the point of origin of the file, and a file pointer to the file.
Entry controlled loop- For loop (The condition is checked at the beginning)
Exit Controlled loop- do-while loop.[7] (The condition is checked in the end, i.e. loop runs at least once)
#include <stdio.h>
int main(void)
{
int arr[] = {20,40};
int *a = arr;
*a++;
printf(“arr[0] = %d, arr[1] = %d, *a = %d”,
arr[0], arr[1], *a);
return 0;
}
Answer:
arr[0] = 20, arr[1] = 40, *p = 40
A block of memory previously allocated can be freed by using free(). The memory can also be released if the pointer holding that memory address is: realloc(ptr,0).
char (*a) (char*);
The stack area is used to store arguments and local variables of a method. It stays in memory until the particular method is not terminated.
sscanf(str, “%d”, &i);
To convert a string value to an integer value.
float num = 1.0;
int a = (int) num;
int b = * (int *) #
The variable stores a value of num that has been first cast to an integer pointer and then dereferenced.
Huge pointers are 32-bit pointers that can be accessed outside the segment, and the segment part can be modified, unlike far pointers.
#include<stdio.h>
main()
{
char *a = “abc”;
a[2] = ‘d’;
printf(“%c”, *a);
}
The program will crash as the pointer points to a constant string, and the program is trying to change its values.
A union is a data type used to store different types of data at the exact memory location. Only one member of a union is helpful at any given time.
Import is a keyword, but #include is a statement processed by pre-processor software. #include increases the size of the code.