What is C language?
C is a mid-level and procedural programming language. The Procedural programming language is also known as the structured programming language is a technique in which large programs are broken down into smaller modules, and each module uses structured code. This technique minimizes error and misinterpretation. More details.
What is an infinite loop?
A loop running continuously for an indefinite number of times is called the infinite loop.
Infinite For Loop:
for(;;){
//code to be executed
}
Infinite While Loop:
while(1){
//code to be executed
}
Infinite Do-While Loop:
do{
//code to be executed
}while(1);
Write a program to check palindrome number in C Programming?
#include
#include
main()
{
int n,r,sum=0,temp;
clrscr();
printf(“enter the number=”);
scanf(“%d”,&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf(“palindrome number “);
else
printf(“not palindrome”);
getch();
}
What is a token?
The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the smallest individual unit in a program. C has the following tokens:
- Identifiers: Identifiers refer to the name of the variables.
- Keywords: Keywords are the predefined words that are explained by the compiler.
- Constants: Constants are the fixed values that cannot be changed during the execution of a program.
- Operators: An operator is a symbol that performs the particular operation.
- Special characters: All the characters except alphabets and digits are treated as special characters.
What is the use of a static variable in C?
Following are the uses of a static variable:
- A variable which is declared as static is known as a static variable. The static variable retains its value between multiple function calls.
- Static variables are used because the scope of the static variable is available in the entire program. So, we can access a static variable anywhere in the program.
- The static variable is initially initialized to zero. If we update the value of a variable, then the updated value is assigned.
- The static variable is used as a common value which is shared by all the methods.
- The static variable is initialized only once in the memory heap to reduce the memory usage.
What is a NULL pointer in C?
A pointer that doesn’t refer to any address of value but NULL is known as a NULL pointer. When we assign a ‘0’ value to a pointer of any type, then it becomes a Null pointer.
What is the difference between near, far and huge pointers?
A virtual address is composed of the selector and offset.
A near pointer doesn’t have explicit selector whereas far, and huge pointers have explicit selector. When you perform pointer arithmetic on the far pointer, the selector is not modified, but in case of a huge pointer, it can be modified.
These are the non-standard keywords and implementation specific. These are irrelevant in a modern platform.
What functions are used for dynamic memory allocation in C language?
- malloc()
- The malloc() function is used to allocate the memory during the execution of the program.
- It does not initialize the memory but carries the garbage value.
- It returns a null pointer if it could not be able to allocate the requested space.
Syntax - ptr = (cast-type*) malloc(byte-size) // allocating the memory using malloc() function.
- calloc()
- The calloc() is same as malloc() function, but the difference only is that it initializes the memory with zero value.
Syntax - ptr = (cast-type*)calloc(n, element-size);// allocating the memory using calloc() function.
- realloc()
- The realloc() function is used to reallocate the memory to the new size.
- If sufficient space is not available in the memory, then the new block is allocated to accommodate the existing data.
Syntax
- ptr = realloc(ptr, newsize); // updating the memory size using realloc() function.
In the above syntax, ptr is allocated to a new size.
free():The free() function releases the memory allocated by either calloc() or malloc() function.
Syntax
free(ptr); // memory is released using free() function.
The above syntax releases the memory from a pointer variable ptr.
Why is C known as a mother language?
C is known as a mother language because most of the compilers and JVMs are written in C language. Most of the languages which are developed after C language has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages.
Write a program to print “hello world” without using a semicolon?
#include
void main(){
if(printf(“hello world”)){} // It prints the ?hello world? on the screen.
}