Program
Clasificado en Tecnología
Escrito el en catalán con un tamaño de 246,79 KB
C Interview Questions And Answers
Page 1
Ques: 1 What is C language?
Ans:
programming language
Ans:
C is a middle level programing language. C is a structured, procedural programming language.c widely used both for operating systems and applications.C is also called a system progmming language
Ans:
The c language is a programming language
Ans:
C is high level language.
Ans:
C is a Structured Oriented Programming Language
Ans:
c is structure programing language.
Ques: 2 What is the output of printf("%d")?
Ans:
0
Ans:
0
Ans:
Any integer value
Ans:
Any integer value
Ans:
the output of this statement depends on data types %d is the data type of int type variabe if you will declare the variable in declaration part suppose u will declare int i so the output of this statement is i...............
Ans:
the output of this statement depends on data types %d is the data type of int type variabe if you will declare the variable in declaration part suppose u will declare int i so the output of this statement is i...............
Ans:
garbegge value
Ans:
garbage integer value
Ans:
Garbage Value
Ques: 3 What is the difference between "calloc(...)" and "malloc(...)"?
Ans:
Some important distance between calloc and malloc are given below: malloc: malloc takes only the "size" of the memory block to be allocated as input parameter. malloc allocates memory as a single contiguous block. if a single contiguous block cannot be allocated then malloc would fail. calloc: calloc takes two parameters: the number of memory blocks and the size of each block of memory calloc allocates memory which may/may not be contiguous. all the memory blocks are initialized to 0. it follows from point 2 that, calloc will not fail if memory can beallocated in non-contiguous blocks when a single contiguous blockcannot be allocated.
Ans:
malloc: malloc create the single block of given size by user calloc: calloc creates multiple blocks of given size both return void pointer(void *)so boh requires type casting malloc: eg: int *p; p=(int*)malloc(sizeof(int)*5) above syntax tells that malloc occupies the 10 bytes memeory and assign the address of first byte to P calloc: eg: p=(int*)calloc(5,sizeof(int)*5) above syntax tells that calloc occupies 5 blocks each of the 10 bytes memeory and assign the address of first byte of first block to P
Ques: 4 What is the difference between "printf(...)" and "sprintf(...)"?
Ans:
the printf() function is supposed to print the output to stdout.In sprintf() function we store the formatted o/p on a string buffer.
Ans:
"printf(....)" is standard output statement and "sprintf(......)" is formatted output statement
Ques: 5 How to reduce a final size of executable?
Ans:
Do not include unnecessary header files and Do not link with unneccesary object files.
Ans:
Use dynamic linking.
Ques: 6 Can you tell me how to check whether a linked list is circular?
Ans:
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\"); } }
Ques: 7 What is the difference between String and Array?
Ans:
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.
Ans:
Array can hold group of element of the same the type, and which allocates the memeory for each element in the array,if we want we can obtain the particular value from an array by giving index value. Ex: int a[10]; a variable holds the values of integer at max 10. String can hold any type of data, but it makes together we can't obtain the particular value of the string. String s="Pra12";
Ques: 8 What is a modulus operator?
Ans:
it gives reminder of any division operation
Ans:
It is an binary arithmetic operator which returns the remainder of division operation. It can used in both floating-point values and integer values. Use of the modulus operator is given below: opLeft % opRight where, opLeft is the left operand and opRight is the right operand. This expression is equivalent to the expression opLeft - ((int) (opLeft / opRight) * opRight)
Ans:
in c language it is used to determine the remainder of any no by deviding the operator if both of them is not float no.
Ans:
it gives remainder part of divisoneg. printf("%d",5%2) output 1
Ques: 9 What are the restrictions of a modulus operator?
Ans:
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�.
Ans:
1)modulus operator works as a%b=reminder (sign as reminder is the sign of a). eg: a)3%2=1, b)3%-2=1, c)-3%2=-1, d)-3%-2=-1 in case a only the answer is correct but not in b,c,and d .that's the limitation of modulus operator . 2) it can't works with float and double
Ques: 10 Which one is faster n++ or n+1?Why??
Ans:
The expression n++ requires a single machine instruction. n+1 requires more instructions to carry out this operation.
Ques: 11 What is equivalent expression for x%8?
Ans:
while(x>8) { x=x-8; } printf("%d",x); Get the remainder
Ques: 12 Which expression always return true?and Which always return false?
Ans:
Expression are given below; if (a=0) always return false. if (a=1) always return true.
Ques: 13 What is Storage class ?
Ans:
There are four type of storage class in C: 1.static 2.auto 3.register 4.extern
Ans:
storage classes in c gives property of the variable, 1.scope of the variable 2.life time 3.memory(either CPU register or memory) four types of C storage classes, 1.automatic 2.register 3.static 4.extern
Ques: 14 what are storage variable ?
Ans:
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
Ques: 15 What are the advantages of auto variables?
Ans:
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.
Ques: 16 What is auto variables?
Ans:
by default variables are auto.as we know that variable changes its character according to the strage class .
Ans:
Auto variable are the default variables. Static memory allocation will happen
Ques: 17 Diffenentiate between an internal static and external static variable?
Ans:
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.
Ques: 18 What are advantages and disadvantages of external storage class?
Ans:
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.
Ques: 19 What are the characteristics of arrays in C?
Ans:
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.
Ques: 20 When does the compiler not implicitly generate the address of the first element of an array?
Ans:
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.
Page 2
Ques: 21 What is modular programming?
Ans:
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.
Ques: 22 What is a function and built-in function?
Ans:
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.
Ques: 23 What is an argument ? differentiate between formal arguments and actual arguments?
Ans:
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.
Ques: 24 What is the purpose of main( ) function?
Ans:
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.
Ques: 25 What is a method?
Ans:
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.
Ques: 26 What are the advantages of the functions?
Ans:
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.
Ques: 27 What is a pointer variable?
Ans:
A pointer variable is used to contain the address of another variable in the memory.
Ques: 28 What is a pointer ?
Ans:
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
Ques: 29 What is a pointer value and address?
Ans:
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.
Ques: 30 Are pointers integers?
Ans:
A pointer is an address not an integer. It should be a +ve number.
Ques: 31 How are pointer variables initialized?
Ans:
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
Ques: 32 What is static memory allocation and dynamic memory allocation?
Ans:
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.
Ques: 33 What is the purpose of realloc( )?
Ans:
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.
Ques: 34 Difference between arrays and pointers?
Ans:
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.
Ques: 35 What is difference between static and global static variable?
Ans:
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
Ques: 36 What are the packages in c?
Ques: 37 How to use floodfill() function ?
Ans:
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
Ques: 38 What is the use of kbhit?
Ans:
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.
Ques: 39 Write a program with out using main() function?
Ans:
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.
Ans:
#include #define nishant(s,t,u,m,p,e,d)m##s##u##t #define nirmal nishant(a,n,i,m,a,t,e) int nirmal() { printf("HELLO Nirmal"); printf("\n"); }
Ans:
#include #define nishant(s,t,u,m,p,e,d)m##s##u##t #define nirmal nishant(a,n,i,m,a,t,e) int nirmal() { printf("HELLO Nirmal"); printf("\n"); }
Ques: 40 Constant volatile variable declaration is possible or not? if give any one example and reason.
Ans:
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.
Ques: 41 How to print 1 to 100 without using any conditional loop?
Ans:
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 #include void main() { int n=1; clrscr(); SHOW: if(n>100) { } else { printf("%d ",n); n+=2; goto SHOW; } getch(); }
Ans:
i don't know whether it will or not #include #include void aa(int); void main() { int a=1; aa(a); getch(); } void aa(int a) { printf("%d",a) a++; aa(a<=100); }="">=100);>
Ques: 42 How pointer variables are initialized ?
Ans:
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" };
Ques: 43 Does mentioning the array name gives the base address in all the integers?
Ques: 44 Explain one method to process an entire string as one unit?
Ans:
using gets
Ques: 45 How can we check whether the contents of two structure variables are same or not?
Ans:
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 #include #include compare(i,j,l) char *i, *j; int l; { int n; for (n=0; n"); scanf("%d %s %lf", &n,s,&d ); str1.a=n; strcpy(str1.s,s); str1.d=d; printf("Enter str2 values (int, char 4, double)-->"); scanf("%d %s %lf", &n,s,&d ); str2.a=n; strcpy(str2.s,s); str2.d=d; strs=compare ((char *)&str1, (char *)&str2, sizeof(struct str)); printf("strs = %d\n", strs); } ;>
Ques: 46 How can we read/write structures from/to data files?
Ans:
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.
Ques: 47 What are bit fields?
Ans:
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.
Ques: 48 If we want that any wildcard characters in the command line argument should be approxiemately expanded , are we required to make any special provision?if yes, which?
Ques: 49 What is the use of bit fields in a structure declaration?
Ans:
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.="">
Ques: 50 What is object file?
Ans:
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.
Ques: 51 How can you access object file?
Ques: 52 What do the functions atoi(),itoa()and gctv()do?
Ans:
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").
Ques: 53 How would you qsort() function to sort an array of structures?
Ans:
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; }
Ques: 54 How would you use qsort() function to sort the name stored in an array of pointers to string?
Ques: 55 How would you use bsearch()function to search a name stored in array of pointers to string?
Ans:
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 #include #include #define TABSIZE 1000 struct node { /* These are stored in the table. */ char *string; int length; }; struct node table[TABSIZE];/*Table to be search*/ . . . { struct node *node_ptr, node; /* Routine to compare 2 nodes. */ int node_compare(const void *, const void *); char str_space[20]; /* Space to read string into. */ . . . node.string = str_space; while (scanf("%s", node.string) != EOF) { node_ptr = (struct node *)bsearch((void *)(&node),(void *)table, TABSIZE,sizeof(struct node), node_compare); if (node_ptr != NULL) { (void)printf("string = %20s, length = %d\n", node_ptr->string, node_ptr->length); } else { (void)printf("not found: %s\n", node.string); } } } /* This routine compare two nodes based on an alphabetical ordering of the string field. */ int node_compare(const void *node1, const void *node2) { return strcoll(((const struct node *)node1)->string,((const struct node *)node2)->string); } 0>
Ques: 56 How to add 2 numbers without + sign?
Ans:
I have given you some examples.Which add 2 numbers with using + sign. Using recursion: #include int add(int m, int n) { if (!m) return n; else return add((m & n) < 1,="" m="" ^="" n);="" }="" int="" main()="" {="" int="" m,n;="" printf("enter="" the="" 2="" numbers:="" \n");="" scanf("%d",&m);="" scanf("%d",&n);="" printf("addition="" is:="" %d",add(m,n));="" }="" m="" ^="" n="" is="" mandatry="" in="" addition="" of="" bits,="" "(a="" &="" b)="">< 1"="" is="" the="" overflow.="" using="" binary="" operator:="" 1="001" 2="010" add(001,="" 010)=""> a -> 001, b-> 010 =011
Ans:
void AddTwoNumbers(int nNumber1,int nNumber2){ int nTemp=0,nSum=0; if(nNumber2 > iNumber1) { nTemp=nNumber2-nNumber1; nNumber2=nNumber2*2; nSum=nNumber2-nTemp; }else { nTemp=nNumber1-nNumber2; nNumber1=nNumber1*2; nSum=nNumber1-nTemp; } }
Ques: 57 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
Ques: 58 How to decide even and odd values without decision making loops?
Ques: 59 How i can run *.bat or *.cmd file by using system function in c ?
Ques: 60 Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }
Ans:
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.
Page 4
Ques: 61 Can there be a mouse click and drag function used together to rotate a circle in c
Ques: 62 Can there be a mouse click and drag function used in c?
Ques: 63 What is the difference between compile time error and run time error?
Ans:
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.
Ques: 64 How to connect a database (MS Access) to Borland C?
Ques: 65 Waht is difference between strdup and strcpy?
Ans:
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");
Ques: 66 What are bit fields? What is the use of bit fields in a structure declaration?
Ans:
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 ;
Ques: 67 Are the variables argc and argv are local to main()?
Ans:
Yes,argc and argv variables are local to main().Because write any thing b/w parenthesis is work as local to that method.
Ques: 68 What are enumerations?
Ans:
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.
Ques: 69 Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]?
Ques: 70 What is the use of typedef?
Ques: 71 Which mistakes are called as token error?
Ques: 72 What is the function of % using in formatted string.
Ques: 73 What is the difference between #include and #include ?file?
Ans:
In C we can include file in program using 2 type: 1.#include 2.#include?file? 1.#include:In this which file we want to include surrouded by angled brakets(<>).In this method preprocessor directory search the file in the predefined default location.For instance,we have given include variable INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS; In this compiler first checks the C:COMPILERINCLUDE directory for given file.When there it is not found compiler checked the S:SOURCEHEADERS directory.If file is not found there also than it checked the current directory. #include method is used to include STANDARDHEADERS, like:stdio.h,stdlib.h. 2.#include?file?:In this which file we want to include surrouded by quotation marks(" ").In this method preprocessor directory search the file in the current location.For instance,we have given include variable INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS; In this compiler first checks the current directory.If there it is not found than it checks C:COMPILERINCLUDE directory for given file.When there it is not found compiler,than checked the S:SOURCEHEADERS directory. #include?file?method is used to include NON-STANDARDHEADERS.These are those header files that created by programmers for use .
Ques: 74 How to print the names of employees or students in alphabetical order using C programming?
Ques: 75 When should we not use Quick sort as a sorting technique?
Ques: 76 How should i rate on the basis of the basis of the scenario the insertion sort , bubble sort , Quick Sort?
Ques: 77 What are comment line arguments in C programing?
Ques: 78 What is the difference between null array and an empty array?
Ans:
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.
Ques: 79 How to write a program to print its own source code?
Ans:
I will given you 2 examples those program print its own source code. In C: #include main() { FILE *fd; int c; fd= fopen("./file.c","r"); while ( (c=fgetc(fd)) != EOF) { printf("%c", c); } fclose(fd); } In C++: #include #include #include #include #include void main() { char ch; clrscr(); fstream fout; fout.open("own_source_code.c",ios::in); if(!fout) { printf("\n can't open"); exit(0); } while(ch!=EOF) { ch=fout.get(); cout;>
Ques: 80 Difference between malloc and calloc?
Ans:
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));
Ques: 81 How much memory does a static variable takes?
Ans:
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.
Ques: 82 What are the uses of pointers in c and c++ language?
Ques: 83 Can we execute printf statement without using semicolan?
Ans:
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.
Ques: 84 How to perform addition,subtraction of 2 numbers without using addition and subtraction operators?
Ques: 85 How to write a program in c to print its own code?
Ans:
#include #include void main() { int x,i,c; char msg[20]; printf("enter the massage"); scanf("%s",msg); printf("enter the number"); scanf("%d",&x); for(i=1;i;i++)>
Ques: 86 What is the function of c?
Ans:
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.
Ques: 87 Is C is platform dependent or independent?how and why?
Ans:
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.
Ques: 88 how to print this : 1 11 121 1331 14641 using for loop
Ans:
void main() { int a[10][10],i,j; for(i=0;i<10;++i) {="" printf("\n");="" for(j="">10;++i)><=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]);="" }="" }="" }="">=i;++j)>
Ans:
String s = ""; int spc = 0; for (int i = 4; i >= 0; i++) { String line = ""; for (int sp = 0; sp < spc;="" sp++)="" {="" line="" +=" " ;="" }="" line="" +="Math.pow(11," i)="" +="" "\n";="" s="line" +="" s;="" spc++;="" }="" print(s);="">
Ques: 89 how to switch the values of two variable without using third variable?
Ans:
I have given a example which switch the values of two variables without using third variable. #include void main() { int val1,val2; val1=5; val2=6; /* now adding val2 to val1 we have */; val1=val2+val1; val2=val1-val2; /* now here val2 will get value of val1 */; val1=val1-val2 /*this will give val1 value of val2 */; }
Ques: 90 #include #include void main() { printf("%d"); getch(); }
Ans:
it's taking the garbage value and output is "0"
Ques: 91 How many nodes do a complete full binary tree with 10 leaves have?
Ques: 92 What is Difference Between C/C++?
Ques: 93 Define the generic programming?
Ques: 94 What are the types of file pointers?and whats the uses of the file pointers?
Ques: 95 How to reverse a string using a recursive function, with swapping?
Ans:
I have given you a solution. That's solve out this problem: #include #include char m1[50]; //GLOABAL VARIABLE. void reverse(int); void main() { int count=0; printf("Enter the given string :"); scanf("%s",m1); for(int i=0;m1[i]!='\0';i++) count++; reverse(count); getch(); } void reverse(int count1) { char temp; static int i=0; if(i!=count) { temp=a1[i]; m1[i]=m1[count1-1]; m1[count1-1]=temp; i++; reverse(--count1); } else printf("\nThe reversed string is :%s",m1); }
Ques: 96 I want to have a program to read a string and print the frequency of each character and it should work in turbo c
Ans:
Our desired program is that, #include #include void main() { int i[26],m,l,n; char str[180]; clrscr(); for(m=0;m<26;m++) i[m]="0;" printf("enter="" a="" string:="" \n");="" gets(str);="" l="strlen(str);" for(m="">26;m++)>;m++)><26;n++) {="" if(str[m]="=(n+66)" ||="" str[m]="=(n" +="" 96))="" a[n]="" +="1;" }="" }="" printf("charecter="" |="" repetation="" \n");="" for="" (n="">26;n++)><26;n++) {="" printf("%c="" |="" %d="" \n="" ",n+64,a[n]);="" }="" getch();="">26;n++)>
Ques: 97 Write a function for strtok()?
Ans:
strtok() function is used to cutting the string into slice.Using this we include string.h header file. How to use: #include char *token; char *line = "LINE TO BE SEPARATED"; char *search = " "; /* Token will point to "LINE". */ token = strtok(line, search); /* Token will point to "TO". */ token = strtok(NULL, search); Example: #include int main() { char *t; char s[40]="welcome at r4r."; p=strtok(s," "); printf("%s",t); do { t=strtok('\0',", "); if(t) printf("|%s",t); }while(t); printf("\n"); } O/P welcome|at|r4r.
Ques: 98 What is the difference between char *a and char a[]?
Ans:
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]
Ans:
char a[]; is an variable of array store elements of same data type. from above the array a[] store only characters can't store integers values. char *a; is an pointer that stores address of the variable. since pointer *a is a variable it also have an address.
Ques: 99 What is a memory leak?
Ans:
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.
Ques: 100 What is difference b/w huge & far & near pointer?
Ans:
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.
Ques: 101 What is the difference between system call and library function?
Ans:
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.
Ques: 102 Whar is the Auto storage class in C ?
Ques: 103 How to convert an char array to decimal array?
Ans:
Using this program you can convert an char array to decimal array: #include int main() { char st[40],*s; char c,speak; do { s=st; printf("Enter the string:"); fgets(st,40,stdin); do { printf("%d ",*s++); }while(*s); printf("\nDo u want to enter other string(y/n)"); speak=getchar(); if(speak=='n') break; }while((c=getchar())!='n'); printf("\n"); }
Ques: 104 How to fill a rectangle using window scrolling in C?
Ques: 105 Explain about storage of union elements.
Ans:
The key point about storage of union elements is that Union elements are use to share common memory space.
Ques: 106 How to differentiate while and do while statement?
Ans:
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 int main(void) { int count = 1; while (count <= 100)="" {="" printf("%d\n",count);="" count="" +="1;" statement="" }="" return="" 0;="" }="" use="" of="" do="" while:="" include="">=> int main(void) { int val, r_digit; printf(�Enter a number to be reversed.\n�); scanf(�%d�, &val); do { r_digit = val % 10; printf(�%d�, r_digit); val = val / 10; } while (val != 0); printf(�\n�); return 0; }
Ques: 107 How to convert a string into integer?
Ans:
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');">='9';m++)>(str))>
Ques: 108 How to print our name without using semicolon in c?
Ans:
I have given you a code that definitely solve your problem. #include int main() { int n; if(printf("vivek")) { n=1; } getch(); }
Ques: 109 How to print value of integers into words?
Ans:
Below i a program to solve given problem: #include int main() { int n; clrscr(); printf("\nEnter the integer number::"); scanf("%d",&n); switch(n) { case:1 printf("\nOne"); break; case:2 printf("\nTwo"); break; case:3 printf("\nThree"); break; case:4 printf("\nFour"); break; case:5 printf("\nFive"); break; case:6 printf("\nSix"); break; case:7 printf("\nSeven"); break; case:8 printf("\nEight"); break; case:9 printf("\nNine"); break; default: printf("\nSorry"); } getch(); }
Ques: 110 What will be the output of x++ + ++x?
Ans:
let, x = 1. Than answer will be. main() { int x=1,y; y = x++ + ++x; printf("/n%d",y); } Ans: y = 3
Ques: 111 what are header files?Can i run program without using header file?
Ans:
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.
Ques: 112 What is macro?
Ans:
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.
Ques: 113 How multiplication take place upto 200 digits?
Ans:
I have given you a program that solve your problem. #include #include #include #include char * mul(char *, char); char * add(char *, char *); void main() { char *no1=(char * )malloc(100); char *no2=(char *)malloc(100); char *u="0"; char *v; int i=0,j=0,t=0,l=0; clrscr(); printf("\n Enter the large no "); gets(no1); printf("\n Enter the second no "); gets(no2); while(l(no2))><=strlen(no2)-l-1;j++) strcat(u,"0");="" v="add(v,u);" l++;="" }="" printf("\n="" multiplication="" is="" %s",v);="" free(no1);="" free(no2);="" }="" char="" *="" mul(char="" *x,="" char="" ch)="" {="" int="" i="0,j=0,t=0;" char="" *v="(char" *)malloc(300);="" char="" *a="(char" *)malloc(300);="" strcpy(u,x);="" strrev(u);="" while(u[i]!='\0' )="" {="" a[j]="(u[i]-48)*(ch-48)+t;" t="a[j]/10;" a[j]="(a[j]%10)+48;" i++;="" j++;="" }="" if(t!="0)" a[j]="t+48;" else="" j--;="" a[j+1]='\0' ;="" strrev(a);="" free(u);="" return(a);="" }="" char="" *="" add(char="" *u,="" char="" *v)="" {="" char="" *t="(char" *)malloc(300);="" int="" i="0,j=0,x=0,a;" strrev(u);="" strrev(v);="" while(u[i]!='\0' &&="" v[i]!='\0' )="" {="" a="(u[i]-48)+(v[i]-48)+x;" x="a/10;" a="a%10;" t[i]="a+48;" i++;="" }="">=strlen(no2)-l-1;j++)>(u))>(v))>
Ques: 114 How to differentiate i++* and *++i?
Ans:
i++* is false representation. *++i->First it increment the value of i,after that is points the value to i.
Ques: 115 What is the difference between getch() and getchar()?
Ans:
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.
Ques: 116 Write a program crashed before reaching main? If happen, how?
Ans:
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); }
Ques: 117 Write a program for 1 232 34543 4567654?
Ans:
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="">=n;i++)>+l;j++)><=j) {="" printf("%d",i+j-k);="" k="k+2;" }="" else="" printf("%d",i+j);="" }="" l++;="" printf("\n");="" }="">=j)>
Ques: 118 What does exit() do?
Ans:
It is used to comes out of execution normally.
Ques: 119 What is the difference between memcpy and strcpy?
Ans:
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.
Ques: 120 How can we handle exceptions in C?
Ans:
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.
Ans:
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.
Ques: 121 How to compare two strings without using the strcmp() function?
Ans:
I have given you a example.In this we compare two strings str1 and str2 without using the strcmp() function. Example: #include #include void stringcompare(char str1[], char str2[]); int main() { char string1[10],string2[10]; printf("\nEnter first String:"); scanf("%s",string1); printf("\nEnter second String:"); scanf("%s",string2); stringcompare(string1,string2); return 0; } void stringcompare(char *str1, char *str2) { int i,j; for(i=0;str1[i]!='\0';i++) { for(j=0;str2[j]!='\0';j++) { if(str1[i] == str2[j]) continue; } } if (i==j) { printf("String str1:%s and str2:%s are EQUAL\n",str1,str2); } else printf("String str1:%s and str2:%s are NOT EQUAL\n",str1,str2); }
Ques: 122 How to access or modify the constt variable in C ?
Ans:
We can not modify the constant variable.
Ques: 123 What is an volatile variable?
Ans:
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.
Ques: 124 How the processor registers can be used in C?
Ans:
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.
Ques: 125 IF **p and &(*p) are same, than tell how?
Ans:
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.
Ques: 126 Can you write function similar to printf()?
Ans:
Here, we write a program similar to printf(). #include int printf(const char * restrict fmt, ...) { va_list list; int i; va_start(list, fmt); i = vfprintf(stdout, fmt, list); va_end(list); return i; }
Ans:
PUTS()
Ques: 127 How to use functions fseek(), freed(), fwrite() and ftell()?
Ans:
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.
Ques: 128 What do you understand about datatype?
Ans:
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.
Ques: 129 What are the data type modifiers?
Ans:
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.
Ques: 130 what are the constants?Explain in brief?
Ans:
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
Ques: 131 How to differentiate b/n definition and declaration?
Ans:
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; }
Ques: 132 How to define their types of variables and initialize them?
Ans:
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.
Ques: 133 What is type casting?Explain it with an example?
Ans:
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
Ques: 134 What are the Array?How to define and declare them?
Ans:
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.="">=>
Ques: 135 What are the Array Indexing?explain.
Ques: 136 What do you understand about String?Explain it.
Ans:
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.
Ques: 137 What are the reserved Keywords?Explain it.
Ans:
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.
Ques: 138 What are the ANSI reserved names in C?
Ans:
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_
Ques: 139 What are the pointers?How to declare them?
Ans:
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;
Ques: 140 What are the Indirection?Explain with an example?
Ans:
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.
Ques: 141 What are the Function Pointer?Explain with an example?
Ans:
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 static void function(int a) { printf("function: %d\n", a); } static void caller(void (*func)(int), int p) { (*func)(p); } int main(void) { caller(function, 10); return 0; }
Ques: 142 What are the Bit Operators?
Ans:
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. }
Ques: 143 What are the External Variables?
Ans:
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.
Ques: 144 How to define structure in C?
Ans:
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 #include int main(void); int main() { int i; struct { char szSaying[129]; int nLength; } MySaying = {�Firestone�s Law of Forecasting:�, strlen(MySaying.szSaying)}; printf(�sizeof(MYSaying)=%d\n�, sizeof(MySaying)); printf(�MySaying %p%3d�%s�\n�, &MySaying.szSaying, MySaying.nLength, MySaying.szSaying); printf(�\n\n�); return (0); }
Ques: 145 How do u understand about structures of arrays?
Ques: 146 How do you define offsetof() Macro?
Ans:
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 #include #include #include struct foo { char *bar; int number; }; // Print a foo the hard way void printFoo(void *foo) { printf("foo->bar: %s\n", *(char **) (foo + offsetof(struct foo, bar))); printf("foo->number: %d\n", *(int *)(foo + offsetof(struct foo, number))); } int main() { struct foo foo = {"A foo", 18}; printFoo(&foo); }
Ques: 147 What the use of malloc() function?
Ans:
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.
Ques: 148 What are the different types of malloc() function in C?
Ans:
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.
Ques: 149 What is the use of calloc() function?
Ans:
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 #include main() { unsigned number; int *pointer; printf("Enter the num(int)to allocate: "); scanf("%d", &number); pointer = (int*)calloc(number, sizeof(int)); if (pointer != NULL) puts("successful Memory allocation ."); else puts(" failed Memory allocation."); return(0); }
Ques: 150 What are the different type of calloc() function?
Ans:
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.
Ques: 151 How to use free() function?
Ans:
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 #include int main () { int *R1, *R2, *R3; R1 = (int*) malloc (10*sizeof(int)); R2 = (int*) calloc (10,sizeof(int)); R3 = (int*) realloc (R2,50*sizeof(int)); free (R1); free (R3); return 0; }
Ques: 152 How to differentiate local memory and global memory?
Ans:
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.
Ques: 153 What is the significance of disk files?
Ans:
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.
Ques: 154 What are the Text Files and Binary Files?
Ans:
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.
Ques: 155 What are the temporary disk files?How to create them?
Ans:
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);
Ques: 156 What are the stream files?
Ans:
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
Ques: 157 What are the stdin and stdout file?
Ans:
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.
Ques: 158 What is the stdaux file?
Ans:
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 #include #include // Standard include items #include // For exit() int main( // Define main() and the fact of program int argc, // uses the passed parameters char *argv[], char *envp[] ); int main(int argc,char *argv[],char *envp[]) { int i; for (i = 0; i < 100;="" i++)="" {="" because="" stdaux="" is="" opened="" in="" the="" binary="" mode,*="" cr/lf="" must="" be="" supplied="" explicitly,="" using="" \n\r*/="" fprintf(stdaux,="" �line="" %2d="" of="" 100="" lines�="" �="" being="" written="" to="" stdaux="" by="" a="" program.\n\r�,="" i);="" }="" return="" (0);="">
Ques: 159 What do you understand about Direct port I/O?
Ans:
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.
Ques: 160 What is the data management?Also define Sorting, merging and purging, Indexed files?
Ans:
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.
Ques: 161 What are the Linked List?
Ans:
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.
Ques: 162 What is the Double LinkedList?
Ans:
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.
Ques: 163 What is the difference b/n Linear search and Binary search?
Ans:
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.
Ques: 164 What do you understand about B-Tree?
Ans:
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.
Ques: 165 What is Thrashing?
Ans:
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'.
Ques: 166 What is a pragma?
Ans:
# 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)
Ques: 167 What is the difference between the Heap and the Stack?
Ans:
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.
Ans:
Stack is volatile memory which uses RAM. where as heap is managed by GC. Stack holds values and heap holds references
Ans:
Stack provides temporary memory allocation,or v can say it stores local variables whose default value is garbage,if not initialised. Whereas heap provides dynamic memory allocation,or memory at run time.
Ques: 168 Why n++ executes faster than n+1?
Ans:
n++ executes faster than n+1 because n++ want only one instruction for execution where n+1 want more one instruction for execution.
Ans:
It(n+1) creates extra memory for adding. Where as n++ refers to same memory.
Ques: 169 What is the difference b/n a linker and linkage?
Ans:
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.
Ques: 170 What is the difference b/n run time binding and compile time binding?
Ans:
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.
Ans:
in compile time binding, memory is allocated during compile time and in runtime binding, memory is allocated during runnin the program
Ques: 171 Write algorithm to reverse a singly linked list.
Ans:
write algorithmto reverse a singly link list
Ques: 172 WHAT IS LIMITATIONS IN C?
Ques: 173 How to use functions in arrarys? it gives a linker error that function is not defined!!
Ques: 174 Write a program to find the squares of n number using do-while.
Ques: 175 sum of all number in between range use recursive function.
Ques: 176 what happen if we declare a constructor after destructor?
Ques: 177 Write a progarm to count number of vowels,consonant,digit spaces and other character type.
Ques: 178 what is hashing?
Ques: 179 What is diference between malloc() and calloc()?
Ques: 180 Write c program to print all even numbers from 56 to 76 including 56 and 76 using loop.
Ques: 201 Write a C program to compute the maximum depth in a tree?
Ques: 202 Is that possible to pass a structure variable to a function/ If so,explain the detailed ways?
Ans:
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); }
Ans:
We can pass a structure variable to a function. for that a variable of type structure is taken as argument in fn and structure variable is passed in fn call.
Ques: 203 write a c program to accept a number between 3 & 10 & print a square of stars. if user enters 4 the output should be as shown **** * * * * ****
Ans:
#include main() { int count; printf("\n**************"); for( count = 1 ; count <= 8="" ;="" ++count)="" print="" f("\n*="" *");="" printf("\n**************\n");="" }="">=>
Ans:
#include #include void main() { int row,i,j,k; printf("enter the no of row::"); scanf("%d",&row); for(i=0;i;i++)>;j++)>;i++)>
Ans:
#include void main() { int count,a; printf("\n-------------------------\n"); printf("\n enter the number="); scanf("%d",&a); if(92) { for( count = 1 ; count <= a="" ;="" ++count)="" print="" f("\n*="" ");="" }="" else="" printf("number="" must="" be="" in="" between="" 3="" to="" 8");="" printf("\n-------------------------\n");="" }="">=>
Ques: 204 What is C?
Ans:
c is super set of all language
Ans:
c is a structured programing language
Ques: 205 string constants should be enclosed with a.single quotes b.double quotes
Ans:
double quotes
Ans:
b
Ans:
b).double quotes
Ans:
b).double quotes
Ans:
b.double quotes
Ans:
double quotes
Ans:
double quotes
Ques: 206 Which of the following is the structure of an if statement? A. if (conditional expression is true) thenexecute this codeend if B. if (conditional expression is true)execute this codeend if C. if (conditional expression is true) {then execute this code>->} D. if (conditional expression is true) then {execute this code}
Ans:
d
Ans:
B
interview
Ques: 21 What is a NULL pointer?
Ans:
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.
Ques: 22 What are macros?
Ques: 23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Nested looping structure C programs
Ques: 24 In the following figure: A B C D E F G H I Each of the digits 1, 2, 3, 4, 5, 6, 7, 8, and 9 is: a)Represented by a different letter in the figure above. b)Positioned in the figure above so that each of A + B + C,C + D +E,E + F + G, and G + H + I is equal to 13. Which digit does E represent? how to solve that type of question.........
Ques: 25 i have an assignement in wihich i have to print a triangle like this: 1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9 please help me how do i print this?
Ques: 26 Explain pointer with the help of an example.
Ques: 27 Write c program to print all even numbers from 56 to 76 including 56 and 76 using loop.
Ques: 28 What is diference between malloc() and calloc()?
Ques: 29 what is hashing?
Ques: 30 Write a progarm to count number of vowels,consonant,digit spaces and other character type.
Ques: 31 what happen if we declare a constructor after destructor?
Ques: 32 sum of all number in between range use recursive function.
Ques: 33 Write a program to find the squares of n number using do-while.
Ques: 34 How to use functions in arrarys? it gives a linker error that function is not defined!!
Ques: 35 WHAT IS LIMITATIONS IN C?
Ques: 36 Write algorithm to reverse a singly linked list.
Ans:
write algorithmto reverse a singly link list
Ques: 37 What is the difference b/n run time binding and compile time binding?
Ans:
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.
Ans:
in compile time binding, memory is allocated during compile time and in runtime binding, memory is allocated during runnin the program
Ques: 38 What is the difference b/n a linker and linkage?
Ans:
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.
Ques: 39 Why n++ executes faster than n+1?
Ans:
n++ executes faster than n+1 because n++ want only one instruction for execution where n+1 want more one instruction for execution.
Ans:
It(n+1) creates extra memory for adding. Where as n++ refers to same memory.
Ques: 40 What is the difference between the Heap and the Stack?
Ans:
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.
Ans:
Stack is volatile memory which uses RAM. where as heap is managed by GC. Stack holds values and heap holds references
Ans:
Stack provides temporary memory allocation,or v can say it stores local variables whose default value is garbage,if not initialised. Whereas heap provides dynamic memory allocation,or memory at run time.
Ques: 41 What is a pragma?
Ans:
# 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)
Ques: 42 What is Thrashing?
Ans:
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'.
Ques: 43 What do you understand about B-Tree?
Ans:
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.
Ques: 44 What is the difference b/n Linear search and Binary search?
Ans:
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.
Ques: 45 What is the Double LinkedList?
Ans:
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.
Ques: 46 What are the Linked List?
Ans:
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.
Ques: 47 What is the data management?Also define Sorting, merging and purging, Indexed files?
Ans:
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.
Ques: 48 What do you understand about Direct port I/O?
Ans:
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.
Ques: 49 What is the stdaux file?
Ans:
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 #include #include // Standard include items #include // For exit() int main( // Define main() and the fact of program int argc, // uses the passed parameters char *argv[], char *envp[] ); int main(int argc,char *argv[],char *envp[]) { int i; for (i = 0; i < 100;="" i++)="" {="" because="" stdaux="" is="" opened="" in="" the="" binary="" mode,*="" cr/lf="" must="" be="" supplied="" explicitly,="" using="" \n\r*/="" fprintf(stdaux,="" �line="" %2d="" of="" 100="" lines�="" �="" being="" written="" to="" stdaux="" by="" a="" program.\n\r�,="" i);="" }="" return="" (0);="">
Ques: 50 What are the stdin and stdout file?
Ans:
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.
Ques: 51 What are the stream files?
Ans:
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
Ques: 52 What are the temporary disk files?How to create them?
Ans:
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);
Ques: 53 What are the Text Files and Binary Files?
Ans:
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.
Ques: 54 What is the significance of disk files?
Ans:
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.
Ques: 55 How to differentiate local memory and global memory?
Ans:
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.
Ques: 56 How to use free() function?
Ans:
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 #include int main () { int *R1, *R2, *R3; R1 = (int*) malloc (10*sizeof(int)); R2 = (int*) calloc (10,sizeof(int)); R3 = (int*) realloc (R2,50*sizeof(int)); free (R1); free (R3); return 0; }
Ques: 57 What are the different type of calloc() function?
Ans:
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.
Ques: 58 What is the use of calloc() function?
Ans:
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 #include main() { unsigned number; int *pointer; printf("Enter the num(int)to allocate: "); scanf("%d", &number); pointer = (int*)calloc(number, sizeof(int)); if (pointer != NULL) puts("successful Memory allocation ."); else puts(" failed Memory allocation."); return(0); }
Ques: 59 What are the different types of malloc() function in C?
Ans:
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.
Ques: 60 What the use of malloc() function?
Ans:
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.
Ques: 61 How do you define offsetof() Macro?
Ans:
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 #include #include #include struct foo { char *bar; int number; }; // Print a foo the hard way void printFoo(void *foo) { printf("foo->bar: %s\n", *(char **) (foo + offsetof(struct foo, bar))); printf("foo->number: %d\n", *(int *)(foo + offsetof(struct foo, number))); } int main() { struct foo foo = {"A foo", 18}; printFoo(&foo); }
Ques: 62 How do u understand about structures of arrays?
Ques: 63 How to define structure in C?
Ans:
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 #include int main(void); int main() { int i; struct { char szSaying[129]; int nLength; } MySaying = {�Firestone�s Law of Forecasting:�, strlen(MySaying.szSaying)}; printf(�sizeof(MYSaying)=%d\n�, sizeof(MySaying)); printf(�MySaying %p%3d�%s�\n�, &MySaying.szSaying, MySaying.nLength, MySaying.szSaying); printf(�\n\n�); return (0); }
Ques: 64 What are the External Variables?
Ans:
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.
Ques: 65 What are the Bit Operators?
Ans:
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. }
Ques: 66 What are the Function Pointer?Explain with an example?
Ans:
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 static void function(int a) { printf("function: %d\n", a); } static void caller(void (*func)(int), int p) { (*func)(p); } int main(void) { caller(function, 10); return 0; }
Ques: 67 What are the Indirection?Explain with an example?
Ans:
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.
Ques: 68 What are the pointers?How to declare them?
Ans:
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;
Ques: 69 What are the ANSI reserved names in C?
Ans:
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_
Ques: 70 What are the reserved Keywords?Explain it.
Ans:
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.
Ques: 71 What do you understand about String?Explain it.
Ans:
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.
Ques: 72 What are the Array Indexing?explain.
Ques: 73 What are the Array?How to define and declare them?
Ans:
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.="">=>
Ques: 74 What is type casting?Explain it with an example?
Ans:
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
Ques: 75 How to define their types of variables and initialize them?
Ans:
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.
Ques: 76 How to differentiate b/n definition and declaration?
Ans:
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; }
Ques: 77 what are the constants?Explain in brief?
Ans:
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
Ques: 78 What are the data type modifiers?
Ans:
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.
Ques: 79 What do you understand about datatype?
Ans:
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.
Ques: 80 How to use functions fseek(), freed(), fwrite() and ftell()?
Ans:
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.
Ques: 81 Can you write function similar to printf()?
Ans:
Here, we write a program similar to printf(). #include int printf(const char * restrict fmt, ...) { va_list list; int i; va_start(list, fmt); i = vfprintf(stdout, fmt, list); va_end(list); return i; }
Ans:
PUTS()
Ques: 82 IF **p and &(*p) are same, than tell how?
Ans:
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.
Ques: 83 How the processor registers can be used in C?
Ans:
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.
Ques: 84 What is an volatile variable?
Ans:
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.
Ques: 85 How to access or modify the constt variable in C ?
Ans:
We can not modify the constant variable.
Ques: 86 How to compare two strings without using the strcmp() function?
Ans:
I have given you a example.In this we compare two strings str1 and str2 without using the strcmp() function. Example: #include #include void stringcompare(char str1[], char str2[]); int main() { char string1[10],string2[10]; printf("\nEnter first String:"); scanf("%s",string1); printf("\nEnter second String:"); scanf("%s",string2); stringcompare(string1,string2); return 0; } void stringcompare(char *str1, char *str2) { int i,j; for(i=0;str1[i]!='\0';i++) { for(j=0;str2[j]!='\0';j++) { if(str1[i] == str2[j]) continue; } } if (i==j) { printf("String str1:%s and str2:%s are EQUAL\n",str1,str2); } else printf("String str1:%s and str2:%s are NOT EQUAL\n",str1,str2); }
Ques: 87 How can we handle exceptions in C?
Ans:
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.
Ans:
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.
Ques: 88 What is the difference between memcpy and strcpy?
Ans:
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.
Ques: 89 What does exit() do?
Ans:
It is used to comes out of execution normally.
Ques: 90 Write a program for 1 232 34543 4567654?
Ans:
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="">=n;i++)>+l;j++)><=j) {="" printf("%d",i+j-k);="" k="k+2;" }="" else="" printf("%d",i+j);="" }="" l++;="" printf("\n");="" }="">=j)>
Ques: 91 Write a program crashed before reaching main? If happen, how?
Ans:
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); }
Ques: 92 What is the difference between getch() and getchar()?
Ans:
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.
Ques: 93 How to differentiate i++* and *++i?
Ans:
i++* is false representation. *++i->First it increment the value of i,after that is points the value to i.
Ques: 94 How multiplication take place upto 200 digits?
Ans:
I have given you a program that solve your problem. #include #include #include #include char * mul(char *, char); char * add(char *, char *); void main() { char *no1=(char * )malloc(100); char *no2=(char *)malloc(100); char *u="0"; char *v; int i=0,j=0,t=0,l=0; clrscr(); printf("\n Enter the large no "); gets(no1); printf("\n Enter the second no "); gets(no2); while(l(no2))><=strlen(no2)-l-1;j++) strcat(u,"0");="" v="add(v,u);" l++;="" }="" printf("\n="" multiplication="" is="" %s",v);="" free(no1);="" free(no2);="" }="" char="" *="" mul(char="" *x,="" char="" ch)="" {="" int="" i="0,j=0,t=0;" char="" *v="(char" *)malloc(300);="" char="" *a="(char" *)malloc(300);="" strcpy(u,x);="" strrev(u);="" while(u[i]!='\0' )="" {="" a[j]="(u[i]-48)*(ch-48)+t;" t="a[j]/10;" a[j]="(a[j]%10)+48;" i++;="" j++;="" }="" if(t!="0)" a[j]="t+48;" else="" j--;="" a[j+1]='\0' ;="" strrev(a);="" free(u);="" return(a);="" }="" char="" *="" add(char="" *u,="" char="" *v)="" {="" char="" *t="(char" *)malloc(300);="" int="" i="0,j=0,x=0,a;" strrev(u);="" strrev(v);="" while(u[i]!='\0' &&="" v[i]!='\0' )="" {="" a="(u[i]-48)+(v[i]-48)+x;" x="a/10;" a="a%10;" t[i]="a+48;" i++;="" }="">=strlen(no2)-l-1;j++)>(u))>(v))>
Ques: 95 What is macro?
Ans:
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.
Ques: 96 what are header files?Can i run program without using header file?
Ans:
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.
Ques: 97 What will be the output of x++ + ++x?
Ans:
let, x = 1. Than answer will be. main() { int x=1,y; y = x++ + ++x; printf("/n%d",y); } Ans: y = 3
Ques: 98 How to print value of integers into words?
Ans:
Below i a program to solve given problem: #include int main() { int n; clrscr(); printf("\nEnter the integer number::"); scanf("%d",&n); switch(n) { case:1 printf("\nOne"); break; case:2 printf("\nTwo"); break; case:3 printf("\nThree"); break; case:4 printf("\nFour"); break; case:5 printf("\nFive"); break; case:6 printf("\nSix"); break; case:7 printf("\nSeven"); break; case:8 printf("\nEight"); break; case:9 printf("\nNine"); break; default: printf("\nSorry"); } getch(); }
Ques: 99 How to print our name without using semicolon in c?
Ans:
I have given you a code that definitely solve your problem. #include int main() { int n; if(printf("vivek")) { n=1; } getch(); }
Ques: 100 How to convert a string into integer?
Ans:
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');">='9';m++)>(str))>
Ques: 121 What is the function of c?
Ans:
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.
Ques: 122 How to write a program in c to print its own code?
Ans:
#include #include void main() { int x,i,c; char msg[20]; printf("enter the massage"); scanf("%s",msg); printf("enter the number"); scanf("%d",&x); for(i=1;i;i++)>
Ques: 123 How to perform addition,subtraction of 2 numbers without using addition and subtraction operators?
Ques: 124 Can we execute printf statement without using semicolan?
Ans:
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.
Ques: 125 What are the uses of pointers in c and c++ language?
Ques: 126 How much memory does a static variable takes?
Ans:
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.
Ques: 127 Difference between malloc and calloc?
Ans:
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));
Ques: 128 How to write a program to print its own source code?
Ans:
I will given you 2 examples those program print its own source code. In C: #include main() { FILE *fd; int c; fd= fopen("./file.c","r"); while ( (c=fgetc(fd)) != EOF) { printf("%c", c); } fclose(fd); } In C++: #include #include #include #include #include void main() { char ch; clrscr(); fstream fout; fout.open("own_source_code.c",ios::in); if(!fout) { printf("\n can't open"); exit(0); } while(ch!=EOF) { ch=fout.get(); cout;>
Ques: 129 What is the difference between null array and an empty array?
Ans:
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.
Ques: 130 What are comment line arguments in C programing?
Ques: 131 How should i rate on the basis of the basis of the scenario the insertion sort , bubble sort , Quick Sort?
Ques: 132 When should we not use Quick sort as a sorting technique?
Ques: 133 How to print the names of employees or students in alphabetical order using C programming?
Ques: 134 What is the difference between #include and #include ?file?
Ans:
In C we can include file in program using 2 type: 1.#include 2.#include?file? 1.#include:In this which file we want to include surrouded by angled brakets(<>).In this method preprocessor directory search the file in the predefined default location.For instance,we have given include variable INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS; In this compiler first checks the C:COMPILERINCLUDE directory for given file.When there it is not found compiler checked the S:SOURCEHEADERS directory.If file is not found there also than it checked the current directory. #include method is used to include STANDARDHEADERS, like:stdio.h,stdlib.h. 2.#include?file?:In this which file we want to include surrouded by quotation marks(" ").In this method preprocessor directory search the file in the current location.For instance,we have given include variable INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS; In this compiler first checks the current directory.If there it is not found than it checks C:COMPILERINCLUDE directory for given file.When there it is not found compiler,than checked the S:SOURCEHEADERS directory. #include?file?method is used to include NON-STANDARDHEADERS.These are those header files that created by programmers for use .
Ques: 135 What is the function of % using in formatted string.
Ques: 136 Which mistakes are called as token error?
Ques: 137 What is the use of typedef?
Ques: 138 Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]?
Ques: 139 What are enumerations?
Ans:
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.
Ques: 140 Are the variables argc and argv are local to main()?
Ans:
Yes,argc and argv variables are local to main().Because write any thing b/w parenthesis is work as local to that method.
Ques: 141 What are bit fields? What is the use of bit fields in a structure declaration?
Ans:
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 ;
Ques: 142 Waht is difference between strdup and strcpy?
Ans:
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");
Ques: 143 How to connect a database (MS Access) to Borland C?
Ques: 144 What is the difference between compile time error and run time error?
Ans:
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.
Ques: 145 Can there be a mouse click and drag function used in c?
Ques: 146 Can there be a mouse click and drag function used together to rotate a circle in c
Ques: 147 Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }
Ans:
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.
Ques: 148 How i can run *.bat or *.cmd file by using system function in c ?
Ques: 149 How to decide even and odd values without decision making loops?
Ques: 150 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
Ques: 151 How to add 2 numbers without + sign?
Ans:
I have given you some examples.Which add 2 numbers with using + sign. Using recursion: #include int add(int m, int n) { if (!m) return n; else return add((m & n) < 1,="" m="" ^="" n);="" }="" int="" main()="" {="" int="" m,n;="" printf("enter="" the="" 2="" numbers:="" \n");="" scanf("%d",&m);="" scanf("%d",&n);="" printf("addition="" is:="" %d",add(m,n));="" }="" m="" ^="" n="" is="" mandatry="" in="" addition="" of="" bits,="" "(a="" &="" b)="">< 1"="" is="" the="" overflow.="" using="" binary="" operator:="" 1="001" 2="010" add(001,="" 010)=""> a -> 001, b-> 010 =011
Ans:
void AddTwoNumbers(int nNumber1,int nNumber2){ int nTemp=0,nSum=0; if(nNumber2 > iNumber1) { nTemp=nNumber2-nNumber1; nNumber2=nNumber2*2; nSum=nNumber2-nTemp; }else { nTemp=nNumber1-nNumber2; nNumber1=nNumber1*2; nSum=nNumber1-nTemp; } }
Ques: 152 How would you use bsearch()function to search a name stored in array of pointers to string?
Ans:
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 #include #include #define TABSIZE 1000 struct node { /* These are stored in the table. */ char *string; int length; }; struct node table[TABSIZE];/*Table to be search*/ . . . { struct node *node_ptr, node; /* Routine to compare 2 nodes. */ int node_compare(const void *, const void *); char str_space[20]; /* Space to read string into. */ . . . node.string = str_space; while (scanf("%s", node.string) != EOF) { node_ptr = (struct node *)bsearch((void *)(&node),(void *)table, TABSIZE,sizeof(struct node), node_compare); if (node_ptr != NULL) { (void)printf("string = %20s, length = %d\n", node_ptr->string, node_ptr->length); } else { (void)printf("not found: %s\n", node.string); } } } /* This routine compare two nodes based on an alphabetical ordering of the string field. */ int node_compare(const void *node1, const void *node2) { return strcoll(((const struct node *)node1)->string,((const struct node *)node2)->string); } 0>
Ques: 153 How would you use qsort() function to sort the name stored in an array of pointers to string?
Ques: 154 How would you qsort() function to sort an array of structures?
Ans:
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; }
Ques: 155 What do the functions atoi(),itoa()and gctv()do?
Ans:
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").
Ques: 156 How can you access object file?
Ques: 157 What is object file?
Ans:
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.
Ques: 158 What is the use of bit fields in a structure declaration?
Ans:
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.="">
Ques: 159 If we want that any wildcard characters in the command line argument should be approxiemately expanded , are we required to make any special provision?if yes, which?
Ques: 160 What are bit fields?
Ans:
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.
Ques: 161 How can we read/write structures from/to data files?
Ans:
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.
Ques: 162 How can we check whether the contents of two structure variables are same or not?
Ans:
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 #include #include compare(i,j,l) char *i, *j; int l; { int n; for (n=0; n"); scanf("%d %s %lf", &n,s,&d ); str1.a=n; strcpy(str1.s,s); str1.d=d; printf("Enter str2 values (int, char 4, double)-->"); scanf("%d %s %lf", &n,s,&d ); str2.a=n; strcpy(str2.s,s); str2.d=d; strs=compare ((char *)&str1, (char *)&str2, sizeof(struct str)); printf("strs = %d\n", strs); } ;>
Ques: 163 Explain one method to process an entire string as one unit?
Ans:
using gets
Ques: 164 Does mentioning the array name gives the base address in all the integers?
Ques: 165 How pointer variables are initialized ?
Ans:
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" };
Ques: 166 How to print 1 to 100 without using any conditional loop?
Ans:
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 #include void main() { int n=1; clrscr(); SHOW: if(n>100) { } else { printf("%d ",n); n+=2; goto SHOW; } getch(); }
Ans:
i don't know whether it will or not #include #include void aa(int); void main() { int a=1; aa(a); getch(); } void aa(int a) { printf("%d",a) a++; aa(a<=100); }="">=100);>
Ques: 167 Constant volatile variable declaration is possible or not? if give any one example and reason.
Ans:
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.
Ques: 168 Write a program with out using main() function?
Ans:
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.
Ans:
#include #define nishant(s,t,u,m,p,e,d)m##s##u##t #define nirmal nishant(a,n,i,m,a,t,e) int nirmal() { printf("HELLO Nirmal"); printf("\n"); }
Ans:
#include #define nishant(s,t,u,m,p,e,d)m##s##u##t #define nirmal nishant(a,n,i,m,a,t,e) int nirmal() { printf("HELLO Nirmal"); printf("\n"); }
Ques: 169 What is the use of kbhit?
Ans:
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.
Ques: 170 How to use floodfill() function ?
Ans:
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
Ques: 171 What are the packages in c?
Ques: 172 What is difference between static and global static variable?
Ans:
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
Ques: 173 Difference between arrays and pointers?
Ans:
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.
Ques: 174 What is the purpose of realloc( )?
Ans:
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.
Ques: 175 What is static memory allocation and dynamic memory allocation?
Ans:
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.
Ques: 176 How are pointer variables initialized?
Ans:
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
Ques: 177 Are pointers integers?
Ans:
A pointer is an address not an integer. It should be a +ve number.
Ques: 178 What is a pointer value and address?
Ans:
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.
Ques: 179 What is a pointer ?
Ans:
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
Ques: 180 What is a pointer variable?
Ans:
A pointer variable is used to contain the address of another variable in the memory.
Ques: 181 What are the advantages of the functions?
Ans:
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.
Ques: 182 What is a method?
Ans:
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.
Ques: 183 What is the purpose of main( ) function?
Ans:
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.
Ques: 184 What is an argument ? differentiate between formal arguments and actual arguments?
Ans:
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.
Ques: 185 What is a function and built-in function?
Ans:
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.
Ques: 186 What is modular programming?
Ans:
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.
Ques: 187 When does the compiler not implicitly generate the address of the first element of an array?
Ans:
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.
Ques: 188 What are the characteristics of arrays in C?
Ans:
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.
Ques: 189 What are advantages and disadvantages of external storage class?
Ans:
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.
Ques: 190 Diffenentiate between an internal static and external static variable?
Ans:
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.
Ques: 191 What is auto variables?
Ans:
by default variables are auto.as we know that variable changes its character according to the strage class .
Ans:
Auto variable are the default variables. Static memory allocation will happen
Ques: 192 What are the advantages of auto variables?
Ans:
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.
Ques: 193 what are storage variable ?
Ans:
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
Ques: 194 What is Storage class ?
Ans:
There are four type of storage class in C: 1.static 2.auto 3.register 4.extern
Ans:
storage classes in c gives property of the variable, 1.scope of the variable 2.life time 3.memory(either CPU register or memory) four types of C storage classes, 1.automatic 2.register 3.static 4.extern
Ques: 195 Which expression always return true?and Which always return false?
Ans:
Expression are given below; if (a=0) always return false. if (a=1) always return true.
Ques: 196 What is equivalent expression for x%8?
Ans:
while(x>8) { x=x-8; } printf("%d",x); Get the remainder
Ques: 197 Which one is faster n++ or n+1?Why??
Ans:
The expression n++ requires a single machine instruction. n+1 requires more instructions to carry out this operation.
Ques: 198 What are the restrictions of a modulus operator?
Ans:
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�.
Ans:
1)modulus operator works as a%b=reminder (sign as reminder is the sign of a). eg: a)3%2=1, b)3%-2=1, c)-3%2=-1, d)-3%-2=-1 in case a only the answer is correct but not in b,c,and d .that's the limitation of modulus operator . 2) it can't works with float and double
Ques: 199 What is a modulus operator?
Ans:
it gives reminder of any division operation
Ans:
It is an binary arithmetic operator which returns the remainder of division operation. It can used in both floating-point values and integer values. Use of the modulus operator is given below: opLeft % opRight where, opLeft is the left operand and opRight is the right operand. This expression is equivalent to the expression opLeft - ((int) (opLeft / opRight) * opRight)
Ans:
in c language it is used to determine the remainder of any no by deviding the operator if both of them is not float no.
Ans:
it gives remainder part of divisoneg. printf("%d",5%2) output 1
Ques: 200 What is the difference between String and Array?
Ans:
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.
Ans:Ex: int a[10];a variable holds the values of integer at max 10.String can hold any type of data, but it makes together we can't obtain the particular value of the string.String s="Pra12";
Array can hold group of element of the same the type, and which allocates the memeory for each element in the array,if we want we can obtain the particular value from an array by giving index value.
Ques: 201 Can you tell me how to check whether a linked list is circular?
Ans:
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\"); } }
Ques: 202 How to reduce a final size of executable?
Ans:
Do not include unnecessary header files and Do not link with unneccesary object files.
Ans:
Use dynamic linking.
Ques: 203 What is the difference between "printf(...)" and "sprintf(...)"?
Ans:
the printf() function is supposed to print the output to stdout.In sprintf() function we store the formatted o/p on a string buffer.
Ans:
"printf(....)" is standard output statement and "sprintf(......)" is formatted output statement
Ques: 204 What is the difference between "calloc(...)" and "malloc(...)"?
Ans:
Some important distance between calloc and malloc are given below: malloc: malloc takes only the "size" of the memory block to be allocated as input parameter. malloc allocates memory as a single contiguous block. if a single contiguous block cannot be allocated then malloc would fail. calloc: calloc takes two parameters: the number of memory blocks and the size of each block of memory calloc allocates memory which may/may not be contiguous. all the memory blocks are initialized to 0. it follows from point 2 that, calloc will not fail if memory can beallocated in non-contiguous blocks when a single contiguous blockcannot be allocated.
Ans:
malloc: malloc create the single block of given size by user calloc: calloc creates multiple blocks of given size both return void pointer(void *)so boh requires type casting malloc: eg: int *p; p=(int*)malloc(sizeof(int)*5) above syntax tells that malloc occupies the 10 bytes memeory and assign the address of first byte to P calloc: eg: p=(int*)calloc(5,sizeof(int)*5) above syntax tells that calloc occupies 5 blocks each of the 10 bytes memeory and assign the address of first byte of first block to P
Ques: 205 What is the output of printf("%d")?
Ans:
0
Ans:
0
Ans:
Any integer value
Ans:
Any integer value
Ans:
the output of this statement depends on data types %d is the data type of int type variabe if you will declare the variable in declaration part suppose u will declare int i so the output of this statement is i...............
Ans:
the output of this statement depends on data types %d is the data type of int type variabe if you will declare the variable in declaration part suppose u will declare int i so the output of this statement is i...............
Ans:
garbegge value
Ans:
garbage integer value
Ans:
Garbage Value
Ques: 206 What is C language?
Ans:
programming language
Ans:
C is a middle level programing language. C is a structured, procedural programming language.c widely used both for operating systems and applications.C is also called a system progmming language
Ans:
The c language is a programming language
Ans:
C is high level language.
Ans:
C is a Structured Oriented Programming Language
Ans:
c is structure programing language.