What is a C Programming language?
C is a powerful general purpose programming language. It is commonly used to program operating system such as UNIX, windows and iOS and also different programming applications. It is fast, portable and available in all platforms.
What are the characteristics of C programming language?
- It is a Procedural and Structured language.
- It is simple, fast and easy to use.
- It produces efficient programs
- It is Integrity, Clarity, efficiency, modularity, generality and Simplicity.
- It can be compiled on a variety of computers.
- It is used to both Low level and high-level programming language
Can you write a basic program in C?
#include
int main()
{
/*………*/
printf( "Hello world " );
getchar();
return 0;
}
#include <Stdio.h>: This is a pre-processor command that includes standard input output header file(stdio.h) from the C library before compiling a C program.
int main() :This is the main function from where execution of any C program begins.
{: beginning of the main function
/*………*/ : Comment section- It won’t be considered for compilation and execution.
Printf(“Hello world”):This command print the output in displayed on the screen.
getchar():This command waits for any character input from keyboard
return 0:this command terminates the main() function and return the value 0
}: End of the main function
Write a C program without using semicolon to print ‘Hello world’?
void main(){
if ( printf ("Hello world")){
}
}
What are the steps to write c program and get the output?
Any C Program:
First: Create
Compile
Execute or Run program
Final: Get the output
Can you explain basic structure of C program?
Document Section: This section consists of comment which include the name of programmer, the author details, time and date of writing the program
Link Section: This section provides instructions to the compiler to link functions from the system library such as using the #include directive.
Definition section: this section defines all symbolic constants such using the #define directive.
Global declaration section: These section global variables that can be used anywhere in the program are declared in global declaration section. This section also declares the user defined functions.
Main() function section: This section contains two parts; declaration part and executable part
Subprogram section: If the program is a multi-function program then the subprogram section contains all the user defined functions that are called in the main () function. User-defined functions are generally placed immediately after the main () function, although they may appear in any order.
What are the static functions in C?
In C, functions are global by default. The “static” keyword before a function name makes it static. Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files.
What are reserved words with a programming language?
The words that are part of the slandered C language library are called reserved words.
Example: Void, Return, int etc.
Can you define Modifier in C?
Modifier is a prefix to the basic data type which used to indicate the modification for storage place allocation to available.
Can you explain indirection?
If you have defined a pointer to a variable or any memory object, there is no direct reference to the value of the variable. This is called indirect reference. But when we declare a variable it has a direct reference to the value.
What are different storage class specifies in C?
- Auto storage
- Register storage
- Static storage
- Extern storage
Can you explain Dangling Pointer in C?
In C, Dangling Pointer is a pointer that doesn’t point to a valid memory location. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.
Can you define Toupper () function in C? And Example?
Toupper () function is converts lowercase alphabet to uppercase alphabet, if the argument passed is a lowercase alphabet.
#include
#include
int main()
{
char c;
c = 'e';
printf("%c -> %c", c, toupper(c));
//Displays the same argument passed if other characters than lowercase character is passed to toupper()//
c = 'A';
printf("\n%c -> %c", c, toupper(c));
c = '8';
printf("\n%c -> %c", c, toupper(c));
return 0;
}
Output:
e -> E
A -> A
8-> 8
How do you access the values within an array?
Arrays contain a number of elements, depending on the size you gave it during variable declaration. Each element is assigned a number from 0 to number of elements-1. To assign or retrieve the value of a particular element, refer to the element number. For example: if you have a declaration that says “intscores[5];”, then you have 5 accessible elements, namely: scores[0], scores[1], scores[2], scores[3] and scores[4].
Can you explain increment statement or decrement statement in C?
One is to use the increment operator ++ and decrement operator –. For example, the statement “x++” means to increment the value of x by 1. Likewise, the statement “x –” means to decrement the value of x by 1. Another way of writing increment statements is to use the conventional + plus sign or – minus sign. In the case of “x++”, another way to write it is “x = x +1”.
Can you explain the Call by Value and Call by Reference?
Call by Value: you are sending the value of a variable as parameter to a function. Call by Value, the value in the parameter is not affected by whatever operation that takes place.
(Or) call by value a copy of actual arguments is passed to respective formal arguments
Call by Reference: Call by Reference sends the address of the variable. Call by Reference, values can be affected by the process within the function.
(Or) call by reference the location (address) of actual arguments is passed to formal arguments, hence any change made to formal arguments will also reflect in actual arguments.
What is the difference between malloc() and calloc()?
calloc():The calloc() function allocates multiple blocks of requested memory.
malloc():The malloc() function allocates a single block of requested memory.
Can you define pointer in C?
A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast.
Can you define array in C?
An Array is a group of similar types of elements. It has a contiguous memory location. It makes the code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed after its declaration.
Arrays are of two types:
One-dimensional array: This array that stores the elements one after another.
Multidimensional array: This array that contains more than one array.
Can you explain Memory leak in C
Memory leak occurs when programmers create a memory in heap and forget to delete it. Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.
Can you explain XOR linked list?
XOR linked list is a Memory Efficient Doubly Linked List. An ordinary Doubly Linked List requires space for two address fields to store the addresses of previous and next nodes.
Can you explain stack in C?
Stack is a linear data structure which follows a particular order in which the operations are performed. Data is stored in stacks using the FILO (First In Last Out) approach. At any particular instance, only the top of the stack is accessible, which means that in order to retrieve data that is stored inside the stack, those on the upper part should be extracted first. Storing data in a stack is also referred to as a PUSH, while data retrieval is referred to as a POP.
Can you explain binary trees?
Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two pointers as well.
Can you define Treap?
Treap is a Balanced binary Search Tree (BBST), but not guaranteed to have height as O(Log n). The idea is to use Randomization and Binary Heap property to maintain balance with high probability
Can you define Splay tree?
A splay tree is a self adjusting binary search tree (BST) with the additional property that recently accessed elements are quick to access again.
Can you explain nested loop?
A nested loop is a loop that runs within another loop. Put it in another sense, you have an inner loop that is inside an outer loop. In this scenario, the inner loop is performed a number of times as specified by the outer loop. For each turn on the outer loop, the inner loop is first performed.
What is the correct program or code to have following output in c using nested for loop?
1
12
123
1234
12345
123456
Program:
#include
int main();
{
int a;
int b;
For (a=1; a<7; a++)
{
For (b=1; b<=a;b++)
{
Printf(“%d”,b);
}
printf()”/n”);
}
return 0;
}
Write a program to reverse a given number in C?
#include
#include
main ()
{
int n, reverse=0, rem;
clrscr();
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
getch();
}
Output: 123
Revers: 321
Write a simple code fragment that will check if a number is positive or negative.
If (num>=0)
printf("number is positive");
else
printf ("number is negative");
Can you explain formal parameters?
In using functions in a C program, formal parameters contain the values that were passed by the calling function. The values are substituted in these formal parameters and used in whatever operations as indicated within the main body of the called function.
Can you explain control structures?
Control structures take charge at which instructions are to be performed in a program. This means that program flow may not necessarily move from one statement to the next one, but rather some alternative portions may need to be pass into or bypassed from, depending on the outcome of the conditional statements.
Can you explain actual arguments?
When you create and use functions that need to perform an action on some given values, you need to pass these given values to that function. The values that are being passed into the called function are referred to as actual arguments.
Can you explain newline escape sequence?
A newline escape sequence is represented by the \n character. This is used to insert a new line when displaying data in the output screen. More spaces can be added by inserting more \n characters. For example, \n\n would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.
Can you explain output redirection?
It is the process of transferring data to an alternative output source other than the display screen. Output redirection allows a program to have its output saved to a file. For example, if you have a program named COMPUTE, typing this on the command line as COMPUTE >DATA can accept input from the user, perform certain computations, then have the output redirected to a file named DATA, instead of showing it on the screen.
Can you explain run-time errors?
These are errors that occur while the program is being executed. One common instance wherein run-time errors can happen is when you are trying to divide a number by zero. When run-time errors occur, program execution will pause, showing which program line caused the error.
Can you explain sequential access file?
In general programs store data into files and retrieve existing data from files. When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. A sequential access file is such that data are saved in sequential order: one data is placed into the file after another. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.
Can you explain variable initialization?
This refers to the process wherein a variable is assigned an initial value before it is used in the program. Without initialization, a variable would have an unknown value, which can lead to unpredictable outputs when used in computations or other operations.
Can you explain FIFO?
In C programming, there is a data structure known as queue. In this structure, data is stored and accessed using FIFO format, or First-In-First-Out. A queue represents a line wherein the first data that was stored will be the first one that is accessible as well.
Can you explain modulus operator?
The modulus operator outputs the remainder of a division. It makes use of the percentage (%) symbol. For example: 10 % 3 = 1, meaning when you divide 10 by 3, the remainder is 1.
What are header files and what are its uses in C programming?
Header files are also known as library files. They contain two essential things: the definitions and prototypes of functions being used in a program. Simply put, commands that you use in C programming are actually functions that are defined from within each header files. Each header file contains a set of functions. For example: stdio.h is a header file that contains definition and prototypes of commands like printf and scanf.
What are the ways to a null pointer can use in C programming language?
Null pointers are possible to use in three ways.
As an error value
As a sentinel value
To terminate indirection in the recursive data structure
Can you explain syntax error?
Syntax errors are associated with mistakes in the use of a programming language. It maybe a command that was misspelled or a command that must was entered in lowercase mode but was instead entered with an upper case character. A misplaced symbol, or lack of symbol, somewhere within a line of code can also lead to syntax error.
Can you convert the string into a number?
The typical C library offers a number of functions intended for converting strings to numbers of just about all formats (longs, floats, integers etc.) and also vice versa, converting numbers to strings.
Can you explain endless loop?
An endless loop can mean two things. One is that it was designed to loop continuously until the condition within the loop is met, after which a break function would cause the program to step out of the loop. Another idea of an endless loop is when an incorrect loop condition was written, causing the loop to run erroneously forever. Endless loops are oftentimes referred to as infinite loops.
Can you explain recursion in C?
When a function calls itself and this process is known as recursion. The function that calls itself is known as a recursive function. Recursive functions are in two phases:
Winding phase
Unwinding phase
Below which operator is incorrect?
( >=, <=, <>, ==)
<> is incorrect. While this operator is correctly interpreted as “not equal to” in writing conditional statements, it is not the proper operator to be used in C programming. Instead, the operator! = must be used to indicate “not equal to” condition.
What is the difference between Compiler and interpreter?
Compilers and interpreters both are deal with how program codes are executed.
Compiler: A compiler is a programming language translator which converts High Level Language program to its equivalent Intermediate Code. Compiler read complete program once and compiles complete code.
Interpreter: An Interpreter is a programming language translator which converts High Level Language program to its equivalent Machine Code. Interpreter reads program line by line or we can say statement by statement and if statement is error free, it converts into machine code.
What is the difference between functions abs() and fabs()?
These 2 functions basically perform the same action, which is to get the absolute value of the given value. Abs() is used for integer values, while fabs() is used for floating type numbers. Also, the prototype for abs() is under <stdlib.h>, while fabs() is under <math.h>.
Can you define Wild Pointers in C?
In c,Uninitialized pointers in the C code are known as Wild Pointers. These are a point to some arbitrary memory location and can cause bad program behavior or program crash.
Can I use int data type to store the value 32768? Why?
No. “int” data type is capable of storing values from -32768 to 32767. To store 32768, you can use “long int” instead. You can also use “unsigned int”, assuming you don’t intend to store negative values.
What is wrong with this statement? myName = Jack;
You cannot use the = sign to assign values to a string variable. Instead, use the strcpy function. The correct statement would be: strcpy(myName, “Jack”);
Can two or more operators such as
and be combined in a single line of program code?
Yes, it’s perfectly valid to combine operators, especially if the need arises. For example: you can have a code like ” printf (“Hello\n\n\’World\’”) ” to output the text “Hello” on the first line and “World” enclosed in single quotes to appear on the next two lines.
Why is it that not all header files are declared in every C program?
The choice of declaring a header file at the top of each C program would depend on what commands/functions you will be using in that program. Since each header file contains different function definitions and prototype, you would be using only those header files that would contain the functions you will need. Declaring all header files in every program would only increase the overall file size and load of the program, and is not considered a good programming style.
Can you explain order of precedence with regards to operators in C.
Order of precedence determines which operation must first take place in an operation statement or conditional statement. On the top most level of precedence are the unary operators!, +, – and &. It is followed by the regular mathematical operators (*, / and modulus % first, followed by + and -). Next in line are the relational operators <, <=, >= and >. This is then followed by the two equality operators == and !=. The logical operators && and || are next evaluated. On the last level is the assignment operator =.
How do you determine the length of a string value that was stored in a variable?
To get the length of a string value, use the function strlen(). For example, if you have a variable named FullName, you can get the length of the stored string value by using this statement: I = strlen(FullName); the variable I will now have the character length of the string value.
Not all reserved words are written in lowercase. TRUE or FALSE?
FALSE. All reserved words must be written in lowercase; otherwise the C compiler would interpret this as unidentified and invalid.
What is the difference between the expression ++a and a++?
In the first expression, the increment would happen first on variable a, and the resulting value will be the one to be used. This is also known as a prefix increment. In the second expression, the current value of variable a would the one to be used in an operation, before the value of a itself is incremented. This is also known as postfix increment.
Can you define endless loop?
An endless loop can mean two things. One is that it was designed to loop continuously until the condition within the loop is met, after which a break function would cause the program to step out of the loop. Another idea of an endless loop is when an incorrect loop condition was written, causing the loop to run erroneously forever. Endless loops are oftentimes referred to as infinite loops.
What is a program flowchart and how does it help in writing a program?
A flowchart provides a visual representation of the step by step procedure towards solving a given problem. Flowcharts are made of symbols, with each symbol in the form of different shapes. Each shape may represent a particular entity within the entire program structure, such as a process, a condition, or even an input/output phase.
How many times interviewgig is get printed?
#include
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("interviewgig");
}
return 0;
}
Output: 0 times
What is the output of this C code?
#include
void main()
{
int b = 5 & 4 | 6;
printf("%d", b);
}
Out Put: 6
Keep up the fantastic piece of work, I read
few posts on this internet site and I believe that
your website is very interesting and contains lots of superb info.