How to perform addition,subtraction of 2 numbers without using addition and subtraction operators?
More interview questions and answers |
---|
Programming language |
0 |
What is the difference between \"calloc(...)\" and \"malloc(...)\"? |
Some important distance between calloc and malloc are given below: |
What is the difference between \"printf(...)\" and \"sprintf(...)\"? |
the printf() function is supposed to print the output to stdout.In sprintf() function we store the formatted o/p on a string buffer. |
Do not include unnecessary header files and Do not link with unneccesary object files. |
Can you tell me how to check whether a linked list is circular? |
First you have to Create two pointers, each set to the start of the list. And Update each as below: while (pointer1) { pointer1 = pointer1->next; pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next; if (pointer1 == pointer2) { print (\"circular\n\"); } } |
Main difference between String and Arrays are: A string is a specific kind of an array with a well-known convention to determine its length where as An array is an array of anything. In C, a string is just an array of characters (type char)and always ends with a NULL character. The �value� of an array is the same as the address of (or a pointer to) the first element; so, frequently, a C string and a pointer to char are used to mean the same thing. An array can be any length. If it�s passed to a function, there�s no way the function can tell how long the array is supposed to be, unless some convention is used. The convention for strings is NULL termination; the last character is an ASCII NULL character. |
it gives reminder of any division operation |
The modulus operator is denoted in c by symbol %. we have two integer values x and y and then the operation x % y called as x modulus y gives the result as (x- (x / y) * y). Say if x=18 and y =5 the x % y gives value as (18- (18 / 5) * 5) which gives (18-15) which results in 3 in other words the remainder of the division operation. But there is a restriction in C language while using the modulus operator. There are two types of numerical data types namely integers, floats, double. But modulus operator can operator only on integers and cannot operate on floats or double. If anyone tries to use the modulus operator on floats then the compiler would display error message as �Illegal use of Floating Point�. |
The expression n++ requires a single machine instruction. n+1 requires more instructions to carry out this operation. |
while(x>8) { x=x-8; } printf("%d",x); Get the remainder |
Which expression always return true?and Which always return false? |
Expression are given below; if (a=0) always return false. if (a=1) always return true. |
There are four type of storage class in C: 1.static 2.auto 3.register 4.extern |
A storage class changes the behavior of a variable. It use to controls the lifetime, scope and linkage. There are five types of storage classes : 1.auto 2.static 3.extern 4.register 5.typedef |
Some main advantages of auto variables are given below: 1.we can use the same auto variable name in different blocks. 2.No side effect by changing the values in the blocks. 3.It used memory economically. 4.Because of local scope auto variables have inherent protection. |
by default variables are auto.as we know that variable changes its character according to the strage class . |
Diffenentiate between an internal static and external static variable? |
Some main difference between internal static and external static are given below: We declare the internal static variable inside a block with static storage class. External static variable is declared outside all the blocks in a file. In internal static variable has persistent storage,no linkage and block scope, where as in external static variable has permanent storage,internal linkage and file scope. |
What are advantages and disadvantages of external storage class? |
Some main advantages and disadvantages of external storage class are given below: advantage: 1.In Persistent storage of a variable retains the updated value. 2.The value is globally available. Disadvantage: 1. Even we does not need the variable the storage for an external variable exists. 2.Side effect may be produce unexpected output. 3.We can not modify the program easily. |
some main characteristics of arrays are given below: 1.all entry in array should have same data type. 2.tables can store values of difference datatypes. |
When does the compiler not implicitly generate the address of the first element of an array? |
When array name appears in an expression such as: 1.array as an operand of the sizeof operator. 2.array as an operand of & operator. 3.array as a string literal initializer for a character array. Then the compiler not implicitly generate the address of the first element of an array. |
It is a programming technique that cut the program function into small modules.Each module has one function that have all codes and variables needed to execute them. Using modular programming we can easily found out the bugs from very large program.Object-oriented programming languages, such as Smalltalk and HyperTalk,incorporate modular programming principles. |
function is that when large program is divided into sub programs.where as each one done one or more actions to be performed for a large program. Those subprograms are called functions.they support only static and extern storage classes. Built-in functions(Library function) that which are predefined and supplied with the compiler called as built-in functions. |
What is an argument ? differentiate between formal arguments and actual arguments? |
Using argument we can pass the data from calling function to the called function. Arguments available in the funtion definition are called formal arguments. Can be preceded by their own data types. We use Actual arguments in the function call. |
Main function is to be called when the program getting started. 1.It is the first started function. 2.Returns integer value. 3.Recursive call is allowed for main() also. 4.it is user-defined function 5.It has two arguments: 5.1)argument count 5.2) argument vector(strings passed) 6.We can use any user defined name as parameters for main(),behalf of argc and argv. |
A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods. It can be re-used in multiple objects. |
Some main advantages of the functions are given below: 1.It makes Debugging easier. 2.Using this we can easily understand the programs logic. 3.It makes testing easier. 4.It makes recursive calls possible. 5.These are helpful in generating the programs. |
A pointer variable is used to contain the address of another variable in the memory. |
Pointers are often thought to be the most difficult aspect of C.A pointer is a variable that points at, or refers to, another variable. That is, if we have a pointer variable of type ``pointer to int,`` it might point to the int variable i |
It is a data object,it refers to a memory location.we numbered every memory locaion in the memory. Numbers that we attached to a memory location is called the address of the location. |
A pointer is an address not an integer. It should be a +ve number. |
We can initialize the Pointer variables by using one of the two ways which are given below: 1.Static memory allocation 2.Dynamic memory allocation |
What is static memory allocation and dynamic memory allocation? |
Information regarding static men\mory allaocaion and dynamic memory allocation are given below: Static memory allocation: The compiler allocates the required memory space for a declared variable.Using the address of operator,the reserved address is obtained and assigned to a pointer variable.most of the declared variable have static memory,this way is called as static memory allocation. In tis memory is assign during compile time. Dynamic memory allocation: For getting memory dynamically It uses functions such as malloc( ) or calloc( ).the values returned by these functions are assingned to pointer variables,This way is called as dynamic memory allocation. In this memory is assined during run time. |
Realloc(ptr,n) function uses two arguments. The first argument ptr is a pointer to a block of memory for which the size is to be altered. The second argument n specifies the new size.The size may be increased or decreased. |
Arrays automatically allocate space with fixed in size and location,but in pointers above are dynamic. array is refered directly to the elements. but pointers refers to address of the elements. |
What is difference between static and global static variable? |
Main difference between static and global static variables are given below: In context of memory it allocated to static variables only once. Static global variable has scope only in the file in which they are declared. outside the file it can not be accessed. but its value remains intact if code is running in some other file |
The main issue of making floodfill function is that it connect the connected pixels of an entire area with same color.It also called Bucket tool in all programming languages. Keep one thing in mind FloodFill function has only compatibility with 16 bits operating system.You should use the ExtFloodFill function with FLOODFILLBORDER. Syntax: BOOL FloodFill( HDC hdc, // handle to DC int nXStart, // starting x-coordinate int nYStart, // starting y-coordinate COLORREF crFill // fill color ); Where: hdc -> Handle to a device context. nXStart->Starting X-Coordinate. nYStart->Starting Y-Coordinate. crFill->Then area to be filled |
kbhit() defined in the header conio.h checks to see if a keystroke is currently available. The available keystroke can be retrieved with getch() of getche(); It returns a non-zero value when there is a keystroke else it returns zero. |
No,we can write a program with out main function, this function is the main function which usually help OS to kill the process that has executed. |
Constant volatile variable declaration is possible or not? if give any one example and reason. |
yes, constant variable declaration is possible. Constants can be defined by placing the keyword const in front of any variable declaration. If the keyword volatile is placed after const, then this allows external routines to modify the variable. Example: An input-only buffer for an external device could be declared as const volatile to make sure the compiler knows that the variable should not be changed and that its value may be altered by processes other than the current program. |
There are 2 ways i have given you. Using these you can solve this problem. 1.Using Recursion: DisplayInfo(Int num = 1) { Printf("%d ", num); if(num == 100) return; else DisplayInfo(++num); } 2. #include |
There are 2 main ways to initialize pointer vaiables.These are: 1.Static Memory Allocation(SMA) 2.Dynamic Memory Allocation(DMA) Some initialization of pointer variables are given below: 1.As Datatype: We can initialize pointer variables as datatype *VariableName(Declaration) e.g. int *ptr,i; It can be initialized as ptr=&i; 2.We can also initialized pointer as: int i; int *ptr; ptr= null; ptr=&i; 3.Below I have given a eg for you. This example defines weekdays as an array of pointers to string constants. static char *weekdays[ ] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; |
Does mentioning the array name gives the base address in all the integers? |
using gets |
How can we check whether the contents of two structure variables are same or not? |
Here below I given a fully tested program which solve your problem. In this i given two structures named str1 and str2. Program return 1 when they have been matched other wise return 0. You can run this program in VC++. #include |
There 2 function given in C++. They are fread() & fwrite(). Using them we can read & write structures from/to data files respectively. Basic representation: fread(&structure, sizeof structure,1,fp); fread function recieves a pointer to structure and reads the image(memory) of the structure as a stream of bytes. Sizeof gives the bytes which was occupied by structure. fwrite(&structure, sizeof structure,1,fp); fwrite function recieves a pointer to structure and writes the image(memory) of the structure as a stream of bytes. Sizeof gives the bytes which was occupied by structure. |
Bit Field is used to make packed of data in a structure.Using bit fields we can communicate Disk drives and OS at alow level.Disk drives have many registers, if want to packed togather in only one register we have to use bit fields. |
In C we store the integer members into the memory space.This memory space saving structures is named as bit fields and declared width in bits explicitly. The Representation of declaring a bit field is given below: >>-specifier_type-+---------+--:-constt_expression-;->< 'declarator' A bit field declaration may not use type qualifiers,constt or volatile. In C, C99 standard requires the allowable data types for bit field to include qualified and unqualified _Boolean, signed integer and unsigned integer. In addition, this supports the following types. # int # long, signed long, unsigned long # short, signed short, unsigned short # char, signed char, unsigned char # long long, signed long long, unsigned long long By default bit field(integer type) is unsigned. |
Object file is used to store the instruction given by machine language and Data. Data should be same as programer used to make an executable program. Object file are of 3 types.Those are given below: 1.An executable file 2.A relocatable file 3.A shared object file 1.An executable file: It has program that does not create problem at execution time. It also display the image of process. 2.A relocatable file: It has Data with their code those does not create link with other object file for make an executable file. 3.A shared object: It store data and their code those suit for link in 2 contexts. 3.1The shared object file with other relocatable and shared object files to create another object file processed by link editor. 3.2 Using dynamic link we combine with an executable file, Other shared objects is used to make image of process. |
In basic term we can say that atoi() is used to change string to integer ,itoa() is used to change integer to string and gctv() is used to change double to sting.Huge knowledge about those are given below: atoi()is used to change strings("65"or"87vivek") into integers, They gives 65 and 87 respectivey. first character isn't a no or -ve, Then atoi returns 0. For atoi it is mandatry one char * argmt and returns int (not a float!). itoa()is used to change integer(65)into string("C"). |
How would you qsort() function to sort an array of structures? |
Using qsort() function we sort an array of structure in c/c++ standard.For Using this function we have to include stdlib.h library. Representation: basic reoresentaion of qsort() function is, void qsort(void *Base, size noe , size width, int (*compar)(constt void *, constt void *)); where: Base-> Pointer indicates beginning of array. noe-> Number of Elements. Width-> Size of Element. Compare-> Does comparison and returns +ve or -ve integer.It is a callback function (pointer to function). Example: This Examples uses structs_sort() function.It is use to compare struct_cmp_product_price() and struct_cmp_product() as compar callbacks.struct_array is used to print structure of array. void structs_sort(void) { struct st_eq structs[] = {{"Computer",24000.0f}, {"Laptop", 40000.0f}, {"Inverter", 10000.0f}, {"A.C.", 20000.0f}, {"Refrigerator", 7000.0f}, {"Mobile", 15000.0f }}; size structs_len = sizeof(structs) / sizeof(struct st_eq); puts("*** Struct sorting (price)..."); /* original struct array */ print_struct_array(structs, structs_len); /* sort array using qsort functions */ qsort(structs, structs_len, sizeof(struct st_ex), struct_cmp_product_price); /* print sorted struct array */ print_struct_array(structs, structs_len); puts("*** Struct sorting (product)..."); /* resort using other comparision function */ qsort(structs, structs_len, sizeof(struct st_eq), struct_cmp_product); /* print sorted struct array */ print_struct_array(structs, structs_len); } /* MAIN program */ int main() { /* run all example functions */ sort_integers(); sort_cstrings(); sort_structs(); return 0; } |
How would you use qsort() function to sort the name stored in an array of pointers to string? |
How would you use bsearch()function to search a name stored in array of pointers to string? |
bsearch, It is a library function.Using this we done data entry in array. Ther is mandatry in binary search your must sorted in ascending order.And do compare two datas.For using this function we have to include stdlib.h library function. Syntax: void *bsearch(void *key, void *base, size num, size width, int (*cmp)(void *emt1, void *emt2)); where; emt->Element. Some steps that we have to follow when we using bsearch. 1. It is passed pointers to two data items 2. It returns a type int as follows: 2.1) <0 Element 1 is less than element 2. 2.2) 0 Element 1 is equal to element 2. 2.3) > 0 Element 1 is greater than element 2. example: #include |
I have given you some examples.Which add 2 numbers with using + sign. Using recursion: #include |
Write a program for n lines 1 2 3 4 5 16 17 18 19 6 15 24 25 30 7 14 23 22 21 8 13 12 11 10 9 |
How to decide even and odd values without decision making loops? |
How i can run *.bat or *.cmd file by using system function in c ? |
In the given example extern int i means we only declare the i.It means compiler think that 'i' only used but does not know which memory is allocated to i,and in next line we call the i but because of missing of memory space it gives a linkage error. |
Can there be a mouse click and drag function used together to rotate a circle in c |
What is the difference between compile time error and run time error? |
Some main differences between compiler time error and run time error are given below: 1.Compile time error are semantic and syntax error. Where Run time error are memory allocation error e.g. segmentation fault. 2.Compile time errors comes because of improper Syntax.Where In java Run time Errors are considered as Exceptions.Run time errors are logical errors. 3.Compile time errors are handled by compiler. where Run time errors are handled by programmers. |
Some main difference b/w strdup and strcpy are given below: 1.strdup: copy a string to a location that will be created by the function. The function will allocate space, make sure that your string will fit there and copy the string. Will return a pointer to the created area. strdup call malloc to allocate storage. Therefor you have to call free when you are not using it. Syntax: char name[] = "Welcome"; char* copy = 0; copy = strdup(name); 2.strcpy:copy a string to a location YOU created (you create the location, make sure that the source string will have enough room there and afterwards use strcpy to copy) strcpy copy from source to destination without doing overflow checking. Syntax: char name[255]; strcpy(name, "Welcome"); |
What are bit fields? What is the use of bit fields in a structure declaration? |
When ever it is necessary to pack several objects into single machine word ,one common use is a set of single bit flags in application like compiler symbol tables.It is called bit fields. A bit field is a set of adjacent bits with a single implementation. Syntax: struct { unsugned int is_keyword : 1; unsigned is_extern :1; unsigned is_static : 1 ; } flags ; flags.is_extern = flags.is_static = 1 ; |
Yes,argc and argv variables are local to main().Because write any thing b/w parenthesis is work as local to that method. |
Enumeration is a kind of type.It is used to hold the group of constt values that are given by programmer.After defining we can use it like integer type.e.g. enum off,on; Here,off and on are 2 integer constants.These are called enumerators.By default value assign to enumurator are off. |
Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]? |
In C we can include file in program using 2 type: 1.#include |
How to print the names of employees or students in alphabetical order using C programming? |
What is the difference between null array and an empty array? |
I will give you some important difference b/n null & empty array. 1.Due to difference in memory allocation, Null array has not allocated memory spaces.Where as Empty array has memory allocated spaces. 2.In an Null array object are not assign to the variables, Where as in an empty array object are assign to the variables. Suppose, It we want to add some values in both array than in case of Null array first we have to assign the object to the variables after that we have to add values.Where as in case of Empty array we have to only add the values. 3.When we declare int* arr[] as globel it has only null that means it is an null array. When array has 0 elements is called empty array. |
I will given you 2 examples those program print its own source code. In C: #include |
Some main and important difference b/n malloc and calloc are given below: malloc is use for memory allocation and initialize garbage values. where as calloc is same as malloc but it initialize 0 value. example: // This allocats 200 ints, it doesn't initialize the memory: int *m = malloc(200*sizeof(int)); // This, too, allocates 200 ints, but initializes the memory // to zero: int *c = calloc(200,sizeof(int)); |
Memory allocated to static variable is not depends on static keyword. only depends on data type.So, it is called an static specifier.It only occupies the values of int,char,float etc.static keyword does not required any memory. example: static int p; static char q; static float r; static short int s; printf(" %d %d %d %d ", sizeof(p), sizeof(q), sizeof(r), sizeof(s)); o/p: 4 1 4 2 (In case of 32 bit compiler) In case of Dos static occupies 2 bytes for integer. |
Yes,We can execute printf statement without using semicolan. When we write printf inside the if,for,while,do while etc it gives output. Example: void main() { if(printf("R4R Welcomes you!")) { /*statements*/ } getch(); } void main() { while(printf("Welcome")) { /*statements*/ } getch(); } int main() { int flag = 1; int test = 10; if (printf("%d",test)) flag = 0; else flag = 1; return 0; } o/p will be 10 and after that when we check the value of flag, it shows 0.return type of printf is int. |
How to perform addition,subtraction of 2 numbers without using addition and subtraction operators? |
#include |
main() function is essential in c programming language.It is function which controls other function those write with in c.These functions are user defined function.C program starts execution from main() function & ends with null statement. main function has three parameters: 1.Environment vector 2.Argument counter 3.Argument vector Function those we write in c program performs one or many specific tasks.main function call those function and given authority of execution to those function. main function call those function first passes execution controls to them.Than execution becomes started.when called function is executed than it returned the controlled to the main function. |
Major issue behind designing C language is that it is a small,portable programming language. It is used to implement an operating system.In past time C is a powerful tool for writing all types of program and has mechanism to achieve all most programming goals.So, we can say that C is platform dependent. |
void main() { int a[10][10],i,j; for(i=0;i<10;++i) { printf("\n"); for(j=0;j<=i;++j) { if(j==0 || i==j) a[i][j]=1; else a[i][j]=a[i-1][j-1]+a[i-1][j]; printf("%4d",a[i][j]); } } } |
how to switch the values of two variable without using third variable? |
I have given a example which switch the values of two variables without using third variable. #include |
How many nodes do a complete full binary tree with 10 leaves have? |
for (int i = 0; i <= 4; i++) |
What are the types of file pointers?and whats the uses of the file pointers? |
How to reverse a string using a recursive function, with swapping? |
I have given you a solution. That's solve out this problem: #include |
Our desired program is that, #include |
strtok() function is used to cutting the string into slice.Using this we include string.h header file. How to use: #include |
Using char*a there is no problem to edit local data.Example: Array is a local data. Where as char a[] is a local pointer to global, static(constt) data.You can not modify the constt data. char *s = "vivek"; +-----+ +---+---+---+---+---+---+------+ | s: | *======> | v | i | v | e | k |'\0'| +-----+ +---+---+---+---+---+---+------+ Pointer Anonymous array char s[] = "vivek"; +----+----+----+----+-----+------+ s: | v | i | v | e | k |'\0' | +----+----+----+----+-----+------+ s[0] s[1] s[2] s[3] s[4] s[5] |
Memory leak is that when memory is allocated but its not released because of an application consume memory reducing the available memory for other applications and causing the system to page virtual memory to the hard drive showing the application or crashing the application. When the computer memory resource limits are reached. example: Suppose, We have allocated 10 bytes to each MemoryArea and NewMemArea. Now,If we execute the statement which is given below: MemoryArea = NewMemArea In this programmer has assigned the MemoryArea pointer to the NewMemArea pointer.So that,the memory location to which MemoryArea was pointing to earlier becomes an orphan. It cannot be freed, as there is no reference to this location. This will result in a memory leak of 10 bytes. Before assigning the pointers, make sure memory locations are not becoming orphaned. |
In old days when Intel introduce hybrid 8bit/16bit family of processors named iAPX 86.(8086 etc) Using this 8bit code changed to the 16bit architecture by 16bit pointers operating with in overlapping segments. A huge pointer is 16:16(Where additional code negotiated segment boundaries). A far pointer is 16:16(Where we can only offset with in the same segment). A near pointer is 16bits. |
What is the difference between system call and library function? |
The key difference b/n system call & library function are given below: 1.System calls are given by system and executed in the system kernel. Than they are called non-portable calls where as library function include ANSI C standard library.So, they are portable. 2.System calls are entry point into the kernel.So, they are not linked with the program. Where as library functions are linked with the program. 3.System calls are given by system,Where as library functions are given by programmer. 4.In system calls,time overhead in calling the system call since a transition has to take place between user mode and kernel mode,Where as time overhead is not required in library function call. 5.In C, We use open() to open a file is a system call,Where as use fopen() to open a file is a library function. |
Using this program you can convert an char array to decimal array: #include |
The key point about storage of union elements is that Union elements are use to share common memory space. |
The key difference b/n while and do while statement is that: 1.In while first checked the condition after that loop is executed. Where as in do while loop is executed at least one time when ever condition is true or false. 2.Syntax for while loop: while (condition checked) { //block of code } Syntax for do while loop: do { //block of code } while (condition checked); 3.Example: Use of while: This program counts from 1 to 100. #include |
I have given you a example. That's solve your problem. int s(char str[]) { int n=0,m; for(int m=0;str[m]>='0' && str[m]<='9';m++) n=10*n+(str[m]-'0'); if(m |
I have given you a code that definitely solve your problem. #include |
Below i a program to solve given problem: #include |
let, x = 1. Than answer will be. main() { int x=1,y; y = x++ + ++x; printf("/n%d",y); } Ans: y = 3 |
what are header files?Can i run program without using header file? |
Basically header files are the library functions.Header files have definitions of functions.These are required to execute the specific operation of function.we write header file with .h extension.Generally these are pre-defined fuctions,But we can also generate our own header file. Example: stdio.h header file is use to perform function like prinf and scanf. conio.h header file is use to perform function like clrscr and getch. |
Macros are the fragment of code.That are used to given a name.When we want to used thew name it is being replaced by content of macros.we can differentiate macros in terms of what they look like & when they are used.Macros are of two types: 1.Object-like macros. 2.Function-like macros. When we used Object-like macros It resembles data objects.Where as when we using function-like macros it resembles function calls. |
I have given you a program that solve your problem. #include |
i++* is false representation. *++i->First it increment the value of i,after that is points the value to i. |
Key difference b/n getch() and getchar() are given below: getch() read the key hits without waiting you to press enter.Where as getchar() does not read key hits and wait till you press enter. |
Write a program crashed before reaching main? If happen, how? |
In C,Using startup functions global variables are initialized before execution of main function.When any errors come in global memories than It can crashed before reaching the main. int foo() { // It comes here before main is invoked //Hence a crash happening in this function obviously ,will happen before main is called // s simple crash :) swprintf(NULL,L"%s",L"crash"); return 1; } int i = foo(); int _tmain(int argc, _TCHAR* argv[]) { return (0); } |
Here, We write a program for given query. int main() { int i,j,k,l=0,n; printf("Enter the given length\n"); scanf("%d",&n); for(i=1;i<=n;i++) { k=2; for(j=0;j |
It is used to comes out of execution normally. |
The key difference between memcpy and strcpy are given below: 1.memcpy is used to copy the NULL bytes even if size is not mentioned,Where as strcpy is stopped copying when it encounters NULL bytes. 2.memcpy can copy null bytes also if the size of memory is given strcpy stops after the first null byte. |
In C we handle exceptions without using try,catch block.Which i used in java,C++ etc.But we can handle exception using validation of data from out side of the world. Example: void main() { int m,n,divide; scanf("%d,%d",m,n); divide=m/n; printf("%d",divide); } In this n may be zero,that generate exception.So,we can avoid them using if statement. if(n==0) print("you have to enter non-zero value"); Using this we only prevent from exception not handle it. |
How to compare two strings without using the strcmp() function? |
I have given you a example.In this we compare two strings str1 and str2 without using the strcmp() function. Example: #include |
We can not modify the constant variable. |
We can not modify the variable which is declare to volatile during execution of whole program. Example: volatile int i = 10; value of i can not be changed at run time. |
using keyword register we can use the process register in C.Basically process register is used to store variables those i want to access frequently.if these registers are not used in any other program,then those registers we used to allocate memory these variables. |
No, **p and &(*P) are not same. Because of &(*P) is used to point the address of variable that was stored in p.Where as **p is used to point the pointer to the another pointer. |
Here, we write a program similar to printf(). #include |
How to use functions fseek(), freed(), fwrite() and ftell()? |
We can use fseek(),fread(),fwrite() and ftell() functions like that, fseek(f,1,item)->Move the pointer for file f a distance 1 byte from location item. fread(s,item1,item2,f)->Enter item2 data items,each of size item1 bytes,from file f to string s. fwrite(s,item1,item2,f)->send item2 data items,each of size item1 bytes from string s to file f. ftell(f)->Return the current pointer position within file f. Functions fread,fseek and fwrite returned type is int and ftell is long int. |
C Language has supported many data types.Which we use writing program.C Language gave authority to programmers to create and use datatypes. Below i have shown you list of basic data types.That are introduce by ANSI standard. datatypes in C: char: required 1 byte and it used for characters or integer variables. int: required 2 or 4 bytes and it used for integer values. float: required 4 bytes and it used for Floating-point numbers. double: required 8 bytes and it used for Floating-point numbers. |
Some data types are to used to effect the characteristic of data object.These are called modifiers.Below i have shown you some modifiers: Data type modifiers in C: long: Forces a type int to be 4 bytes (32 bits) long and forces a type double to be larger than a double (but the actual size is implementation defined). short: Forces a type int to be 2 bytes (16 bits) long. unsigned: Causes the compiler (and CPU) to treat the number as containing only positive values. Because a 16-bit signed integer can hold values between �32,768 and 32,767, an unsigned integer can hold values between 0 and 65,535. The unsigned modifier can be used with char, long, and short (integer) types. |
When we declare any variable as constant than we can't be modify the value of that variable at run time.Constants can come in any data type that the C compiler supports. A special constant, the string, can be used to either initialize a character array or be substituted for one. Some constant in C: 123: int,In the smallest size and type that will hold the value specified. 123U: unsigned int,in the smallest size and type that will hold the value specified. 123L: long int,signed 123UL: long int,unsigned 'A': Character constant "ABCD": Character string constant 7.89:double-floating-print constant 7.89F:float-floating-print constant 7.89F:long double-floating-point constant |
Some useful difference b/n definition and declaration are given below: When define an object not only its attribute are made known,but its object are also created.Where as when we declare an object only its attribute are made known. Example: We define object like; long int lSum; long int lCount; void SumInt(int nItem) { lSum =lSum + (long)nItem; ++lCount; } We declare an object like; void VFunction(int nType) { int nTest; nTest = nType; } |
Variables are made by programmers.It can be modified.When we defined any data object as a singular variable can be defined also as an array. In C variable are of many type. Like: an integer or character, or may be of compound data objects(Like: structure or unions). Initialization of variable: int num; //Here we declare num variable as integer and it is initialized as default size. int num=0; //Here we declare num variable and initialize them with 0. |
The key role of type casting is that converting a variable of one type into anther type. Given below i have shown you a example of conversion of data types in C: Original Original Type casting After type data type in decimal casting long int 123123123 to short int 46515 short int 12345 to char '9' long double 123123123123to integer 2864038835 |
Basically Array are the collection of same data type.It has common name and addressed as a group. Declaration of an Array: We have to declare Array also as a single data object. int Array[10]; In this array of integers are created.Than first member in the array are addressed as Array[0] and last member has been declared as Array[9]. Example: #define MAX_SIZE 10 int Array[MAX_SIZE]; int n; for (n = 1; n <= MAX_SIZE; n++) { Array[n] = n; } Definition of an Array: We know that we declare an array like that, int Array[10]; When an array is external, it must be defined in any other source files that may need to access it. Because you don�t want the compiler to reallocate the storage for an array, you must tell the compiler that the array is allocated externally and that you want only to access the array. |
Basically C does not support an String.But C has many library functions using them we can over come that problem. String are Array of type char.String constant(like: "this is our first string")can be consider as Character Array. |
Some keywords are reserved in ANSI C.This keyword we can use as such they have given.Before using those keywords keep one thing in mind the are lowercase.Some main ANSI C reserved are given below: asm: Begins assembly code and is not part of the ANSI standard. FORTRAN: The entry follows FORTRAN calling conventions; FORTRAN may be in lowercase for some implementations and is not part of the ANSI standard. PASCAL: The entry follows PASCAL calling conventions; PASCAL may be in lowercase for some implementations and is not part of the ANSI standard. Generally, the PASCAL conventions are identical to FORTRAN�s. const: The variable will be used as a constant and will not be modified. volatile: The compiler may make no assumptions about whether the variable�s value is current. This keyword limits optimization, and possibly slows program execution. signed: The variable is a signed integer (with the actual size unspecified). auto: The variable is created when the function is called, and is discarded when the function exits. An auto variable is not initialized by the compiler. continue: Passes control to the next iteration of a do(), for(), or while() statement. enum: An integer defining a range of values. The actual internal representation of the value is not significant. extern: The object is defined in a different source file. |
I have given you a ANSI C reserved names and their uses given below: %: This is used to printf()/scanf() format string. is..or to..: Lowercase function names beginning with either is or to,where the next character also is a lowercase letter. str..,mem..or wcs..: Lowercase function names beginning with either str, mem, or wcs, where the next character also is a lowercase letter E: Macros that begin with an uppercase E SIG.. or SIG_..: Macros that begin with either an uppercase SIG or SIG_ ...f or ...l: Existing math library names with a trailing f or l LC_: Macros that begin with an uppercase LC_ |
Pointers are may be of variable or constant.The contains the address of object.Some important characteristics of pointers are given below: 1.Pointer is used to contain the address of any object.It may be an array,a singular variable,a union and a structure. 2.It is also used to store the address of a function. 3.It can not hold the address of the constant. Remember that when a pointer getting incremented than its value is incremented by the sizeof() the pointer's type. We can declare and initialize the pointer like that: int counter= 0; int *pcounter; pcounter = &counter; |
You have a pointer, what do you do with it? Because it�s part of your program,you can�t write your address on it and nail it to a tree so that your friends can find your home. You can, however, assign to a pointer the address of a variable and pass it to a function, and then the function can find and use the variable. C operator * is called the indirection operator.C to use whatever the pointer variable is pointing to and use the value contained in the memory that the pointer is pointing to. |
Using function pointer we can do almost anything with function name.We can pass parameters to a function that is called as pointer.A classic example is the library function qsort(), which takes a pointer to a function. This pointer often is coded as a constant; you might, however, want to code it as a function pointer variable that gets assigned the correct function to qsort()�s compare. I have given you a example of Function pointer. function named function() is defined which will be called through a function pointer. A function named caller() accepts as parameters a function pointer and an integer, which will be passed as arguments to the function that will be called by caller(). #include |
Bit operators are different frm logical operator. So,don't confuse with them.The keyword TRUE signifies a true bit (or bits) that is set to one, and FALSE signifies a bit (or bits) that is set to zero. Some Bitwise Operators are given below: &: Performs a bitwise AND operation. If both operands are TRUE, the result is TRUE; otherwise, the result is FALSE. |: Performs a bitwise OR operation. If either operand is TRUE, the result is TRUE; otherwise, the result is FALSE. ^: Performs a bitwise exclusive OR operation. If both operands are TRUE or both operands are FALSE, the result is FALSE. The result is TRUE if one operand is TRUE and the other is FALSE. Exclusive OR is used to test to see that two operands are different. <<: Shifts the X operand, Y operand bits to the left. For example, (1 << 4) returns a value of 8. In bits, (0001 << 4) results in 1000. New positions to the left are filled with zeroes. This is a quick way to multiply by 2, 4, 8, and so on. >>: Shifts the X operand, Y operand bits to the right. For example, (8 >> 4) returns a value of 1. In bits, (1000 >> 4) results in 0001. New positions to the right are filled with ones or zeroes, depending on the value and whether the operand being shifted is signed. This is a quick way to divide by 2, 4, 8, and so on. // Using a bitwise AND: if (x & y) { // With x == 1, and y == 2, this will NEVER be TRUE. } |
We use single include file to create both a definition and a declaration for an external variable.Scope of external variable is global.Every byte of memory allocated for an external variable is initialized to zero. |
To define structure in C we use struct keyword. Using structure we can form different groups according to their specialty. Syntax of defining an structure are given below: struct tag_name { type member_name; type member_name; type member_name; } structure_name = {initializer_values}; Example of an structure: #include |
ANSI C introduce a new macro called offsetof().This is use to determine the offset of a member in a structure. Using offsetof() we can easy to compute the amount of storage used by individual members of a structure. Example of offsetof() macro are given below: #include |
malloc() function is used for memory allocation in ANSI C standard.malloc() function requires only one parameters. For using malloc() function we have to follow some rules. Which are given below: 1.The malloc() function returns a pointer to the allocated memory or NULL if the memory could not be allocated. 2.The pointer returned by malloc() should be saved in a static variable, unless you are sure that the memory block will be freed before the pointer variable is discarded at the end of the block or the function. 3.You should always free a block of memory that has been allocated by malloc()when you are finished with it. If you rely on the operating system to free the block when your program ends, there may be insufficient memory to satisfy additional requests for memory allocation during the rest of the program�s run. 4.Avoid allocating small blocks (that is, less than 25 or 50 bytes) of memory.There is always some overhead when malloc()allocates memory�16 or more bytes are allocated in addition to the requested memory. |
Some malloc() functions of C with their function and description are given below: void * malloc( size_t size ); : The ANSI C standard memory allocation function. void _ based( void ) *_bmalloc( _ segment seg, size_t size ); : Does based memory allocation.The memory is allocated from the segment you specify. void _ far *_fmalloc( size_tsize ); : Allocates a block of memory outside the default data segment, returning a far pointer. This function is called by malloc()when the large or compact memory model is specified. void _ near *_nmalloc( size_t size ); : Allocates block of memory inside the default data segment, returning a near pointer. This function is called by malloc() when the small or medium memory model is specified. |
Calloc() function is used to initialize memory. Calloc() function is used to allocates a group of object. Syntax of allocating Calloc() function are given below: void *calloc(size_t number, size_t size); Where, size_t-> is a synonym for unsigned. number-> is the num of object to allocate. size-> It shows the size of each object in bytes. When memory allocation with calloc() function is successful,than function returns a pointer. Otherwise,it returns 0. Example: #include |
Some main calloc() function with their description are given below: Function Description void *calloc(size_t num, The ANSI C standard array size_t size ); memory allocation function. void _ based(void) Using this you can write *_bcalloc( _segment seg, the segment that the size_t num, size_t size );data will be allocated from. void _ far *_fcalloc Allocates a block of (size_t num,size_t size);memory outside the default data segment, return far pointer.We call this function when big mem model is used. void_near*_ncalloc Allocates a block of (size_t num,size_t size);memory inside the default data segment, return near pointer. This function is used when small/medium memory model specified. |
Free() function is used to return the memory to the operating system after use.Because is most of time very limited source.So,we have to try to made max output. Example: #include |
Local and global memory allocation is applicable with Intel 80x86 CPUs. Some main difference b/n local and global variables are given below: 1.Using local memory allocation we can access the data of the default memory segment,Where as with global memory allocation we can access the default data,located outside the segment,usually in its own segment. 2.If our program is a small or medium model program , the default memory pool is local,Where as If our program uses the large or compact memory model, the default memory pool is global. |
Without files it is impossible to make program. Because without input we can't expect about output and unable to save result without files.ANSI C has huge collection of I/O functions.These files are called disk files. Programmer can made a file in an unformatted (machine readable) manner,or program can write to a file in a formatted (people readable) manner. |
Text Files: Text Files are those files that are display on the screen.These files are readable files.It has not uses only few special characters like,tab and newlines.Text Files generally introduce by programmers. Binary Files: Binary Files are those files that can contain any data, including the internal representation of numbers, special control characters. |
All most large programs with large with large data objects do not even try to save all their data in memory.they only read the data,index the data,and than than write the file in Temporary disk files. Some rules of creating files are given below: 1.The file name must be unique. This uniqueness can be guaranteed by using tmpfile() or tmpnam(). 2.The file must be deleted when you have finished using it. If you create the file using tmpfile(), the operating system deletes the file for you. If you create it with tmpnam() and an explicit open, your program must delete the file. Syntax of creating files are given below: FILE *TempFile = tmpfile(); // Lines of code to use the file fclose(TempFile); |
We can open file in C with using stream files.which are identified with a pointer to a FILE structure, or as low-level files, which are identified with an integer handle. We ca open stream files with using one of the following functions. fopen(): Opens the specified file with the specified mode freopen(): Closes the file specified, then opens a new file as specified fdopen(): Opens a duplicate stream file for an already open low-level file |
We can open stdin file using operating system. Basically it touched with keyboard.It comes from an I/O redirected file. Some functions used by stdin are given below: getchar(): Use to get character from stdin gets(): Use to get a string from stdin scanf(): Use to performs a formatted read from stdin stdout�s output goes to a redirected file.Program to use the screen by opening a file called con. Some functions used by stdin are given below: printf(): Use to performs a formatted write to stdout putchar(): use to writes a character to stdout puts(): Writes the buffer to stdout vprintf(): Performs a formatted write to stdout. The output is pointed to by a parameter-list pointer. |
First i tell you about about aux device.We can defined aux device as the main serial communication port (not the console serial communication port). aux is defined as COM1: and stdaux writes to the COM1: port. Example: #include |
Direct Port I/O are of system dependent from type of computer and configuration of computer.It may be dangerous when we use this uncarefully. Some main Direct I/O functions are given below: inp(): Use to Inputs a byte of data from the specified port inpw(): Use to Inputs two bytes of data from the specified port outp(): Use to Outputs a byte of data to the specified port outpw(): Outputs two bytes of data to the specified port Always it returns type int,All output function returns in terms of byte or word and input function return currently input byte or word. |
What is the data management?Also define Sorting, merging and purging, Indexed files? |
In data management we consider two things: 'what to manage' and 'how to manage'.What to manage is very important because in that we consider about Additional and accompanying information, chiefly documentation, code and command files. For achieving that we uses many methods like sorting,merging,purging and indexed files. Sorting: We use that to sort data in a particular manner as our need.It increase the searching of data efficiently. Merging: This is used to combine two sorted files and generate a resultant sorted files. Purging: It is uses to create the new file from the sorted file and eliminate the duplicate lines of the original file from the sorted files. Indexed file: It consists of two files.main data file and smaller index file. |
Basic definition of linked list is that An linked list is a list of data items in which each data item points to the next data item(except last item). In linked list we start with a pointer that points to the first element of the list.after that next element points to its successor element.Last element has a NULL pointer that indicates the end of the list. Linked are of three type: 1.Doubly linked list 2.Ordered linked list 3.Circular Linked list We construct linked list using these functions: LinkedList()//It is used to construct an empty list. LinkedList(Collection extends E>c)//It is used to construct a list elements with specific location. |
Double Linked List is that each data item in the list can point both side(next or previous)data item. It is not specific type means it may be of stack or queue.This is use to increase the performance of program.It is also called as Two-way Linked List or Symmetrically Linked list. |
The main difference b/n Linear search and Binary search are given below: Linear search: Linear search starts to search first records of the list and going on until it finds the matched record or to the end of list.In Linear Linked list their is no need to sort the file in a particular order. Binary search: Their is three steps you have to follow when you using Binary search. 1.It starts with to select the middle item of the list.When the key item is less than the selected item than Binary search take the item between the current item and the start element of the list.Otherwise, if key item is greater than the selected item than Binary search take the item between the current item and the last element of the list.Benefit of its is that after taking one comparison it delete the half list. 2.If key item is less than the current item than we only take half list who is less than the key.Otherwise,If key item is greater than the current item than we only take half list who is greater than the key.And start in again. 3.We repeat step2 till we not reached our desired key. |
When we uses B-Tree. Each data object has a key, all the key who are less than the given are placed on left side where as key who are greater than the given key are placed on the right side. Using this method key maintain a tree like structure for the given list of item.Some, Important terms that we generally used in B-Tree are given below: Node: Indicates the data items 0f the list in B-Tree. Root node: Indicates the first node in B-Tree. Left side: Which data items on the left side and less than the current item. Right side: Which data items on the Right side and greater than the current item. balance: This is use to check the tree is balance or not. |
Thrashing is that in which a computer takes the much type to load the data from secondary memory to main memory or main memory to secondary memory as compare to execution of loaded data. When we divide memory into pages than thrashing from this is called 'page thrashing'. |
# pragma preprocessor directive is use to allow the compiler to do the some specific operation of compiler.pragma has on and off command using them we can enable or disable some compiler operations. Suppose, In our program loop does not perform his operation may be it happen because of pragma. 1.If we want to enable the operation of loop using pragma. Than we have to write like that, #pragma loop_opt(on) 2.If we want to disable the operation of loop using pragma. Than we have to write like that, #pragma loop_opt(off) |
The main difference b/n the Heap and the Stack are given below: 1.In stack we create object temporary where programmer used to reserve allocation.' 2.stack not have automatic garbage collection where as heap have automatic garbage collection. |
n++ executes faster than n+1 because n++ want only one instruction for execution where n+1 want more one instruction for execution. |
The key difference b/n linker and linkage is that linker is used to change an object code into an executable code by linking together the necessary build in functions.Place where we declare the variable in a program is called the linkage of variable. |
What is the difference b/n run time binding and compile time binding? |
When the address of functions are determined a run time than it is called run time or dynamic binding or late binding.While when the address of functions are determined a compile time than it is called compile time or static binding or early binding. |
write algorithmto reverse a singly link list |
How to use functions in arrarys? it gives a linker error that function is not defined!! |
Write a program to find the squares of n number using do-while. |
Write a progarm to count number of vowels,consonant,digit spaces and other character type. |
Write c program to print all even numbers from 56 to 76 including 56 and 76 using loop. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Nested looping structure C programs |
A ptr that is not pointing to any valid programming address is called as null ptr.also it can point to 0x0000 If trying to deference the null ptr in c,its throws segmentation fault. |
Int *p=NULL: |
How do you reverse a linked list without using any C pointers? |
How would you detect a loop in a linked list? Write a C program to detect a loop in a linked list. |
Write a C program to determine the number of elements (or size) in a tree. |
Write a C program to find the minimum value in a binary search tree. |
Is that possible to pass a structure variable to a function/ If so,explain the detailed ways? |
yes it is possible to pass structure variable to a function struct emp { int eno; }; void disp(struct emp e) { printf(e.eno); } void main() { struct emp e; e.eno=10; disp(e); } |
#include |
c is super set of all language |
string constants should be enclosed with a.single quotes b.double quotes |
double quotes |
d |
Different data types for different types of data in C are Primary Data Types Secondary Data Types |
There are many data type for different different Purposes. int unsigned long long int float long long int unsigned long int long int unsigned int unsigned short int short int double char signed char unsigned char long long double |
4 Storage Classes in C language : 1.auto 2.register 3.static 4.extern |
int : %d float : %f char : %c string : %s address : %u etc. |