Anda di halaman 1dari 35

1. Difference between arrays and pointers? Arrays use subscripted variables to access and manipulate data.

Pointers are used to manipulate data using the address 2. What is the purpose of realloc ( )? The realloc function changes the size of the object pointed to by ptr to the size specified by size 3. What is static memory allocation and dynamic memory allocation? Static memory allocation refers to the process of allocating memory at compile-time . dynamic memory allocation is allocation at runtime 4. Are pointers integers? A pointer holds a memory address, from 0 to the upper limit of your memory (in 32 bit addressing this is up to 2^32, 64 bit is up to 2^64 bytes). So in math terms, a pointer could be considered a non-negative integer. 5. What is a pointer variable? - YES

6. What is a method?

7. What are the advantages of the functions? It minimizes codes

8. What is the purpose of main( ) function? It is where program starts 9. What is an argument? Differentiate between formal arguments and actual arguments?

Argument is a value that is either coming frm outside or going out to some other function. Formal argument is the incoming value into a fn frm main. Actual argument is the original variable and its value 10.What is a function and built-in function? A function in C language is a block of code that performs a specific task. It has a name and it is reusable i.e. it can be executed from as many different parts in a C Program as required. It also optionally returns a value to the calling program 11.What is modular programming? Modular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish this

12.When does the compiler not implicitly generate the address of the first element of an array? Whenever an array name appears in an expression such as array as an operand of the sizeof operator array as an operand of & operator array as a string literal initializer for a character array Then the compiler does not implicitly generate the address of the address of the first element of an array. 13.What are the characteristics of arrays in C? 1) 2) An array holds elements that stored in have the same memory data type

Array elements are

subsequent

locations

3) Two-dimensional array elements are stored row by row in subsequent memory locations. 4) Array name represents the address of the starting element

14.Differentiate between a linker and linkage? A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

15.What are advantages and disadvantages of external storage class? Advantages 1)Persistent 2)The Disadvantages storage value of of of a external variable is external retains globally storage storage the latest class value

available class

1)The storage for an external variable exists even when the variable is not needed 2)The side 3)Modification effect may of the produce program surprising is output difficult

4)Generality of a program is affected 16.Diffenentiate between an internal static and external static variable? An internal static variable is declared inside a block with static storage class whereas an external static variable is declared outside all the blocks in a file.An internal static variable has persistent storage,block scope and no linkage.An external static variable has permanent storage,file scope and internal linkage. 17.What are the advantages of auto variables?

the main advantage of auto variable is if we use auto variable in different block of our code with different value then it has not any side-effect because it is automatically managed by the compiler . 18.What is storage class and what are storage variable? There are four types of storage classes in C. These are used to store variables. These are Extern, Static, Register and Auto. Auto is the default class assigned to any variable. eg. if we define int x=10; then it means auto int x=10 register and static differ in only one grounds that register is there in the cpu and static in the main memory. extern is global and can be accessed by any program and anywhere.

19.Which expression always return true? Which always return false? If(1) always true, if(0)- always false 20.Write the equivalent expression for x%8? Int int a=x/8; remainder=x-(a*8); will give the same result as of x%8 a=0; remainder=0;

21.Why n++ executes faster than n+1?

22.What is a modulus operator? What are the restrictions of a modulus operator? 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.

23.What is the difference between a string and an array? String can hold only char data. Where as an array can hold any data type. - An array size can not be changed. Where as a string size can be changed if it is a char pointer - The last element of an array is an element of the specific type. The last character of a string is a null \0 character. - The length of an array is to specified in [] at the time of declaration (except char[]). The length of the string is the number of characters + one (null character). 24.Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name? Array subscripts are ultimately resolved into pointer form. Like a[i] -> *(a+i). So the pointer form is always better. Program running time will be reduced but for a programmer array declarations are simple 25.Can the sizeof operator be used to tell the size of an array passed to a function? No. There?s no way to tell, at runtime, how many elements are in an array parameter just by looking at the array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to the first element. 26.Is using exit() the same as using return? No. The exit() function is used to exit your program and return control to the operating system. The return statement is used to return from a function and return control to the calling function. 27.Is it possible to execute code even after the program exits the main() function? Generally no, but possible with atexit() fn

The standard C library provides a function named atexit() that can be used to perform "cleanup" operations when your program terminates. You can set up a set of functions you want to perform automatically when your program exits by passing function pointers to the atexit() function. Here's an example of a program that uses the atexit() function: 28.What is a static function? If u declare a fn as static then it is not accessable from outside or other main function 29.Why should I prototype a function? A function prototype tells the compiler what kind of arguments a function is looking to receive and what kind of return value a function is going to give back. This approach helps the compiler ensure that calls to a function are made correctly and that no erroneous type conversions are taking place. 30.How do you print an address? Use print f and print pointer directly it will give u the address, if u print *p it gives value 31.Can math operations be performed on a void pointer? No. Pointer addition and subtraction are based on advancing the pointer by a number of elements. Bydefinition, if you have a void pointer, you don?t know what it?s pointing to, so you don?t know the size of what it?s pointing to. If you want pointer arithmetic to work on raw addresses, use character pointers. 32.How can you determine the size of an allocated portion of memory? simply if u want to know how much memory is allocated to character u can use the following printf("%d",size of(3)); this statement tells how much space does 3 takes

33.What is a null pointer assignment error? What are bus errors, memory faults, and core dumps? A NULL pointer assignment is a runtime error It occurs due to various reasons one is that ur program has tried to access an illegal memory location. Illegal location means either the location is in the operating systems address space or in the other processes memory space. In stdio.h NULL is defined as 0 So whenever your program tries to access 0th location the operating system kills your program with runtime assignment error because the 0th location is in the operating systems address space and operating system doesnt allow access to its address space by user program . A bus error is trying to access memory that can't possibly be there. You've used an address that's meaningless to the system, or the wrong kind of address for that operation.

34.What is the difference between NULL and NUL? NULL can be defined as ((void*)0), NUL as '\0'. 35.What is the heap? The heap is the section of computer memory where all the variables created or initialized at runtime are stored. 36.Can the size of an array be declared at runtime? Yes. consider

the

piece

of

code

shown

below,

main() { int printf("Enter scanf("%d",&size); int /* . */ }

array

size; size"); array[size]; code

Remaining

Theoratically,this is true but this type of code is not implemented in realtime application.This type of code is poor programming practise but still the code works. 37.What is the stack? the conceptually simplest way of saving information in a temporary storage location for such common computer operations as mathematical expression evaluation and recursive subroutine calling. 38.When should a far pointer be used? Far pointer can address memory location which is not pointed by normal pointer. Normal pointer being 2 byte can address up to 65536. If we are using programs where we need huge memory access we use far pointers 39.What is the difference between far and near? If we need to address more than 64k mem we go for far pointer 40.Why should we assign NULL to the elements (pointer) after freeing them? This is paranoia based on long experience. After a pointer has been freed, you can no longer use the pointed-to data. The pointer is said to dangle; it doesn?t point at anything useful. If you NULL out or zero out a pointer immediately after freeing it, your program can no longer get in trouble by using that pointer 41.When would you use a pointer to a function? we use pointer to function when 1.we want to pass address in function 2.in case of array we can acces whole array in function's definiton by passing it's base address

42.How do you use a pointer to a function? Has to find out 43.Can you add pointers together? Why would you? No..pointer addition in not allowed as the address obtained by adding two pointers, may exceed the memory size 44.What does it mean when a pointer is used in an if statement? To see if it a null pointer and also to see if two pointers are pointing to the same location by comparing them 45.Is NULL always defined as 0? To be found out 46.What is a void pointer? A void pointer is a C convention for a raw address. The compiler has no idea what type of object a void Pointer really points to. 47.What is a null pointer? When referring to computer memory, a null pointer is a command used to direct a software program or operating system to an empty location in the computer memory. 48.How many levels of pointers can you have? To be found out 49.What is indirection? If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value. 50.How do you print only part of a string?

by using extract method newstring = strextract(3,7) print newstring int char printf("Enter scanf("%s",&s); printf(" Enter the start scanf("%d for(p=i;p<=j;p++) { printf("%c",*(s+p); } getch() }

we

can extract a

part

from

the

string

the

i=0,j=0,p; *s; String");

and

end

of

the

string: "); %d",&i,&j);

51.how can I convert a string to a number? The parseInt() and parseFloat() functions can be used to convert a String variable into an integer or Number. 52.How can I convert a number to a string? itoa() function can be used 53.What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used? memcpy copies the specified number of bytes of src to dest. strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. 54.How can you check to see whether a symbol is defined? You can use the #ifdef and #ifndef preprocessor directives to check whether a symbol has been defined (#ifdef) or whether it has not been defined (#ifndef). Many programmers like to ensure that their own

version of NULL is defined, not someone else's. This task can be accomplished as shown here: #ifdef NULL #undef NULL #endif #define NULL (void*) 0 The first line, #ifdef NULL, checks to see whether the NULL symbol has been defined. If so, it is undefined using #undef NULL and the new definition of NULL is defined. To check whether a symbol has not been defined yet, you would use the #ifndef preprocessor directive. 55.How do you override a defined macro? You can use the #undef preprocessor directive to undefine (override) a previously defined macro. And then newly define it. There is no such procedure as overriding a macro 56.What is #line used for? The #line preprocessor directive is used to reset the values of the _ _LINE_ _ and _ _FILE_ _ symbols, respectively. This directive is commonly used in fourth-generation languages that generate C language source files. 57.What is a pragma? The #pragma pre-processor directive allows each compiler to implement compiler-specific features that can be turned on and off with the #pragma statement. For instance, your compiler might support a feature called loop optimization. This feature can be invoked as a command-line option or as a #pragma directive. 58.What are the standard predefined macros? The ANSI C standard defines six predefined macros for use in the C language: Macro Name Purpose _ _LINE_ _ Inserts the current source code line number in your code. _ _FILE_ _ Inserts the current source code filename in your code.

_ _ Inserts the current date of compilation in your code. _ _TIME_ _ Inserts the current time of compilation in your code. _ _STDC_ _ Is set to 1 if you are enforcing strict ANSI C conformity. _ _cplusplus Is defined if you are compiling a C++ program.

59.How can type-insensitive macros be created? A type-insensitive macro is a macro that performs the same basic operation on different data types. This task can be accomplished by using the concatenation operator to create a call to a type-sensitive function based on the parameter passed to the macro. 60.How many levels deep can include files be nested? Even though there is no limit to the number of levels of nested include files you can have, your compilermight run out of stack space while trying to include an inordinately high number of files. This number varies according to your hardware configuration and possibly your 61.Can include files be nested? Yes, header files can be nested to any level. As long few good programming practices are followed: 1. Always use header file guarding to avoid multiple inclusions. This will cause issues during compilation. The compiler is going to complain about redeclaration/redeffinition of variables 2. Avoid circular inclusions. This is one of bigger blunders a naive programmer would do. This becomes impossible to resolve unless proper care is taken to design the header file structure in large projects 62.Can you define which header file to include at compile time? -

63.Is it better to use a macro or a function? The answer depends on the situation you are writing code for. Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called. There is no overhead involved in using a macro like there is in placing a call to a function. 64.How are portions of a program disabled in demo versions?

If you are distributing a demo version of your program, the preprocessor can be used to enable or disable portions of your program. The following portion of code shows how this task is accomplished, using the preprocessor directives #if and #endif: int save_document(char* doc_name) { #if DEMO_VERSION printf(?Sorry! You can?t save documents using the DEMO version of this program!n?); return(0); #endif ... }

65.What is the benefit of using an enum rather than a #define constant? What is enum, then question answer to be found 66.What is the benefit of using #define to declare a constant? Using the #define method of declaring a constant enables you to declare a constant in one place and use it throughout your program. This helps make your programs more maintainable, because you need to maintain only the #define statement and not several instances of individual constants throughout your program. 67.Can a file other than a .h file be included with #include?

Yes, any file 68.How can you avoid including a header more than once? One easy technique to avoid multiple inclusions of the same header is to use the #ifndef and #define preprocessor directives. When you create a header for your program, you can #define a symbolic name that is unique to that header. You can use the conditional preprocessor directive named #ifndef to checkwhether that symbolic name has already been assigned. If it is assigned, you should not include the header, because it has already been preprocessed. If it is not defined, you should define it to avoid any further inclusions of the header. The following header illustrates this technique: #ifndef #define #define #define #if #define #else #define #endif #endif _FILENAME_H _FILENAME_H ?1.00.00? ?08/01/94? _ ?WINDOWS? ?DOS?

VER_NUM REL_DATE _WINDOWS_ OS_VER OS_VER

69.What will the preprocessor do for a program? The C preprocessor is used to modify your program according to the preprocessor directives in your source code. A preprocessor directive is a statement (such as #define) that gives the preprocessor specific instructions on how to modify your source code. The preprocessor is invoked as the first part of your compiler program's compilation step. It is usually hidden from the programmer because it is run automatically by the compiler.

70.What is a macro, and how do you use it? 71.How can I make sure that my program is the only one accessing a file?

By using the sopen() function you can open a file in shared mode and explicitly deny reading and writingpermissions to any other program but yours. fileHandle = SH_DENYWR); sopen(?C:DATASETUP.DAT?, O_RDWR,

72.How can I open a file so that other programs can update it at the same time? 73.How do you determine whether to use a stream function or a low-level function? 74.What is the difference between text and binary modes?

75.How can you restore a redirected standard stream?

76.How do you redirect a standard stream? Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen, it can be redirected to a file or printer port. Similarly, your program's input (stdin) can come from a file rather than the keyboard. In DOS, this task is accomplished using the redirection characters, < and >. For example, if you wanted a program named PRINTIT.EXE to receive its input (stdin) from a file named STRINGS.TXT, you would enter the following command at the DOS prompt: C:>PRINTIT < STRINGS.TXT

Notice that the name of the executable file always comes first. The less-than sign (<) tells DOS to take the strings contained in STRINGS.TXT and use

them

as

input

for

the

PRINTIT

program.

Redirection of standard streams does not always have to occur at the operating system. You can redirect a standard stream from within your program by using the standard C library function named freopen(). For example, if you wanted to redirect the stdout standard stream within your program to a file named OUTPUT.TXT, you would implement the freopen() function as shown here: ... freopen("output.txt", ...

"w",

stdout);

Now, every output statement (printf(), puts(), putch(), and so on) in your program will appear in the file OUTPUT.TXT.

77.How can I search for data in a linked list? The only way to search a linked list is with a linear search, because the only way a linked lists members can be accessed is sequentially. Sometimes it is quicker to take the data from a linked list and store it in a different data structure so that searches can be more efficient. 78.How can I sort a linked list? Insertion sort technique 79.What is hashing? Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value. It is also used in many encryption algorithms. 80.What is the quickest searching method to use ? quick sort, merge sort, and radix sort. The Quick Sort The quick sort algorithm is of the divide and conquer type. That means it works by reducing a sorting problem into several easier sorting problems and solving each of them. A dividing value is chosen from the input data, and the data is partitioned into three sets: elements that belong before the

dividing value, the value itself, and elements that come after the dividing value. The partitioning is performed by exchanging elements that are in the first set but belong in the third with elements that are in the third set but belong in the first Elements that are equal to the dividing element can be put in any of the three setsthe algorithm will still work properly. The Merge Sort The merge sort is a divide and conquer sort as well. It works by considering the data to be sorted as a sequence of already-sorted lists (in the worst case, each list is one element long). Adjacent sorted lists are merged into larger sorted lists until there is a single sorted list containing all the elements. The merge sort is good at sorting lists and other data structures that are not in arrays, and it can be used to sort things that dont fit into memory. It also can be implemented as a stable sort. The Radix Sort The radix sort takes a list of integers and puts each element on a smaller list, depending on the value of its least significant byte. Then the small lists are concatenated, and the process is repeated for each more significant byte until the list is sorted. The radix sort is simpler to implement on fixed-length data such as ints. 81.What is the easiest searching method to use? qsort() was the easiest sorting method, because it is part of the standard library 82.How can I sort things that are too large to bring into memory? quick sort can be an external sort. The data can be partitioned by writing it to two smaller files. When the partitions are small enough to fit, they are sorted in memory and concatenated to form the sorted file. 83.What is the quickest sorting method to use? Quick sort http://en.wikipedia.org/wiki/Sorting_algorithm go through this link and the table in it, it is worth to see it once Programs: 1. What will print out? main() { char *p1=name; char *p2; p2=(char*)malloc(20);

memset while(*p2++ printf(%sn,p2); }

(p2, =

0,

20); *p1++);

Answer:empty string. 2. What will be printed as the result of the operation below: main() { x=y++ y= printf(%d%dn,x,y); } Answer : 5794 3. What will be printed as the result of the operation below: main() { int printf(%d,%d,%dn,x,x< <2,x>>2); } Answer: 5,20,1 4. What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void main() { int swap printf(%d printf(%d } int { swap2(int int a, int x=5; ++y + + int x=20,y=35; x++; ++x;

x=5,

y=10; (x,y); %dn,x,y); swap2(x,y); %dn,x,y); b) temp; temp=a; b=a;

a=temp; return 0; } Answer: 10, 5 10, 5 5. What will be printed as the result of the operation below: main() { char printf(%sn,ptr); } Answer:Cisco Systems isco systems 6. What will be printed as the result of the operation below: main() { char char s1[]=Cisco; s2[]= systems; printf(%s,s1); *ptr *ptr++; = Cisco Systems; printf(%sn,ptr); ptr++;

} Answer: Cisco 7. What will be printed as the result of the operation below: main() { char char *p2; p1=(char p2=(char *)malloc(25); strcpy(p1,Cisco); strcpy(p2,systems); strcat(p1,p2); printf(%s,p1); } Answer: Ciscosystems *p1; *)malloc(25);

8. The following variable is available in file1.c, who can access it?: 9. static int average; Answer: all the functions in the file1.c can access the variable. 10.WHat will be the result of the following #define TRUE 0 // some code while(TRUE) { // some code } Answer: This will not go into the loop as TRUE is defined as 0. 11.What will be printed as the result of the operation below: int int { } int { } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); x; modifyvalue() return(x+=10); changevalue(int x) return(x+=1); code?

printf("First output:%dn",x); x++; printf("Second printf("Third output:%dn",x); } Answer: 12 , 13 , 13 changevalue(x); output:%dn",x); modifyvalue();

12.What will be printed as the result of the operation below: main() { int x y printf(%d %dn,x,y); } Answer: 11, 16 13.What will be printed as the result of the operation below: main() { int printf(Cisco printf(Cisco Systemsn); } Answer: Two lines with Cisco Systems will be printed. a=0; if(a==0) Systemsn); x=10, = = y=15; x++; ++y;

Q:What is the difference between ordinary variable and pointer in C? A: An ordinary variable is like a container it can hold any value and we can change the value of ordinary variable at a time throughout the program .A pointer is a variable that stores the address of another Variable. C interview question: In printf() Function- What is the difference between "printf(...)" and "sprintf(...)"? Answer: sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device. :What will be the output of the following code? void main () { int i = 0 , a[3] ; a[i] = i++; printf (%d",a[i]) ; } Answer: The output for the above code would be a garbage value. In the statement a[i] = i++; the value of the variable i would get assigned first to a[i]

i.e. a[0] and then the value of i would get incremented by 1. Since a[i] i.e. a[1] has not been initialized, a[i] will have a garbage value. :Explain the functions memcmp( ) and memicmp( ) Answer:The functions memcmp( ) and memicmp( ) compares first n bytes of given two blocks of memory or strings.However, memcmp( ) performs comparison as unsigned chars whereas memicmp( ) performs comparison as chars but ignores case (i.e. upper or lower case). Both the functions return an integer value where 0 indicates that two memory buffers compared are identical. If the value returned is greater than 0 then it indicates that the first buffer is bigger than the second one. The value less than 0 indicate that the first buffer is less than the second buffer. The sizeof( ) function doesnt return the size of the block of memory pointed to by a pointer. Why? Answer:The sizeof( ) operator does not know that malloc( ) has been used to allocate a pointer. sizeof( ) gives us the size of pointer itself. There is no handy way to find out the size of a block allocated by malloc( ). What is a stack ? Answer: The stack is a region of memory within which our programs temporarily store data as they execute. For example, when a program passes parameters to functions, C places the parameters on the stack. When the function completes, C removes the items from the stack. Similarly, when a function declares local variables, C stores the variable's values on the stack during the function's execution. Depending on the program's use of functions and parameters, the amount of stack space that a program requires will differ. How do I write code that executes certain function only at program termination? Answer: Use atexit( ) function as shown in following program. #include main( ) { int ch ; void fun ( void ) ; atexit ( fun ) ; // code } void fun( void ) { printf ( "\nTerminate program......" ) ; getch( ) ; }

:What are memory models? Answer: The compiler uses a memory model to determine how much memory is allocated to the program. The PC divides memory into blocks called segments of size 64 KB. Usually, program uses one segment for code and a second segment for data. A memory model defines the number of segments the compiler can use for each. It is important to know which memory model can be used for a program. If we use wrong memory model, the program might not have enough memory to execute. The problem can be solved using larger memory model. However, larger the memory model, slower is your program execution. So we must choose the smallest memory model that satisfies our program needs. Most of the compilers support memory models like tiny, small, medium, compact, large and huge. :How does C compiler store elements in a multi-dimensional array? Answer:The compiler maps multi-dimensional arrays in two waysRow major order and Column order. When the compiler places elements in columns of an array first then it is called column-major order. When thecompiler places elements in rows of an array first then it is called row-major order. C compilers store multidimensional arrays in row-major order. For example, if there is a multi-dimensional array a[2][3], then according row-major order, the elements would get stored in memory Q:Can we get the mantissa and exponent form of a given number? A:The function frexp( ) splits the given number into a mantissa and exponent form. The function takes two arguments, the number to be converted as a double value and an int to store the exponent form. The function returns the mantissa part as a double value. Q:What is access( ) function... A:The access( ) function checks for the existence of a file and also determines whether it can be read,written to or executed. Q:How do I convert a floating-point number to a string? A: Use function gcvt( ) to convert a floating-point number to a string. Q:How do I determine amount of memory currently available for allocating? A: We can use function coreleft( ) to get the amount of memory available for allocation. Q:When we open a file, how does functions like fread( )/fwrite( ), etc. get to know from where to read or to write the data?

A: When we open a file for read/write operation using function like fopen( ), it returns a pointer to the structure of type FILE. This structure stores the file pointer called position pointer, which keeps track of current location within the file. :How do I write code to get the current drive as well as set the current drive? A: The function getdisk( ) returns the drive number of current drive. The drive number 0 indicates 'A' as the current drive, 1 as 'B' and so on. The Setdisk( ) function sets the current drive. Q:What is the difference between "printf(...)" and"sprintf(...)"? A:sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device. Q:What does static variable mean? A:There are 3 main uses for the static. 1. If you declare within a function:It retains the value between function calls 2.If it is declared for a function name:By default function is extern..so it will be visible from other files if the function declaration is as static..it is invisible for the outer files 3. Static for global variables:By default we can use the global variables from outside files If it is static global..that variable is limited to with in the file 4. and also when static is defined for normal variables it puts its values to zero Q:What is the difference between ordinary variable and pointer in C? A An ordinary variable is like a container it can hold any value and we can change the value of ordinary variable at a time throughout the program .A pointer is a variable that stores the address of another Variable. Q:What are segment and offset addresses? A: When paging technique is performed, the page will breaks into segments and its sequence is said to be segments and its width can be said as offset. In short,segment is a physical address and offset is logical address. Q:What is "far" and "near" pointers in "c" ? A:Near" and "far" pointers are actually non-standard qualifiers that you'll find only on x86 systems. They reflect the odd segmentation architecture of Intel processors. In short, a near pointer is an offset only,which refers to an address in a known segment. A far pointer is a compound value, containing both a segment number and an offset into that segment Q: What is Type casting?

A: Type casting is an operation in c where one variable type can be converted into another

Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name? Array subscripts are ultimately resolved into pointer form. Like a[i] -> *(a+i). So the pointer form is always better. What is the difference between null array and an empty array? null array----when the size of array is not declared than the array is known as null array. EMPTY ARRAY-------if an array having the size but not values than it's known as empty array. EX = null array b[]; empty array b[size of array]; Can we add the name as "Mixed Arrays" instead of the name given as "Structures" in c?why the name structure is given? How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....) num%2?printf("This is Odd number"):printf("This is even number"); This can also be done using switch statement Switch(num%2) { Case Printf(?This is Break; Case Printf (?This is } why n++ executes faster than n+1?

odd

1: number?); 0: Number?);

even

Can include files be nested? Yes. Include files can be nested any number of times. Is NULL always defined as 0?

#include<stdio.h> int { if(NULL==(void printf("true"); else printf("false"); if(NULL printf(" Value getch(); } == is

main() *)0)

0) zero");

What is the difference between #include <file> and #include file #include<file> This will refer the given file in the standard input and output directory. but #include"file" This will first refers the given file in the current directory if this not found it will refers in the standard input and output directory.

How do you override a defined macro? An #ifdef #undef #endif #define MACRO X c is a middle level language that come in category of structural programming language so there is noconcept of overriding.one method to do this is to #undef the defined macro and then give new definition to macro. elegant way of doing this is shown below: MACRO MACRO

Write the equivalent expression for x%8?

int int a=x/8; remainder=x-(a*8); will give the same result as of x%8 What is the difference between NULL and NUL?

a=0; remainder=0;

basically NULL points the predefined value zero to the compiler !! and NUL is the name of 1st character in the ASCII character set!! Is there anything you can do in C++ that you cannot do in C ? The things which we can do in 1)overloading 2)inheritance 3)polymorphisms 4)dynamic allocation of variables c++ but not in c are :-

How to write a C program for displaying a sentence without output command?

How can we use data connectivity in 'c' language? Using Pro *C we can do the data connectivity. Define structural language and procedural language? What is :- Asembler , compiler , Preprocessor , laxical analysis , parsing ?

Can we execute printf statement without using semicolan yes main() it can be done

{ while(printf("saurabh,saswat,vinay")) {} } What is a macro, and how do you use it? A macro is a preprocessor directive that provides a mechanism for token replacement in your source code. Macros are created by using the #define statement. What are storage class in c? Storage class specifies where the variable will be store,it also indicate the scope and life time of the variable. Scope of the variable determines in which part of the value of the variable is active and life time of the variable refers to the duration of the value of the variable that would last long. There are 4 types of storage class. 1.automatic 2.external 3.static 4.register which one will execute faster if(flag==0) or if (0==flag) and why? The first one is wright :-)(flag==0)

What are the packages in c? Is it better to use malloc() or calloc()? malloc is better then calloc.

Internally,calloc calls malloc and then fills with zeros.Hence, two calls is required,one for allocating memory and another call to fill zero's.Hence,calloc is less efficient than malloc. Why does malloc(0) return valid memory address ? What's the use ?

malloc(0) does not return a non-NULL under every implementation. An implementation is free to behave in a manner it finds suitable, if the allocation size requested is zero. The implmentation may choose any of the following actions: * A null pointer is returned.

* The behavior is same as if a space of non-zero size was requested. In this case, the usage of return value yields to undefined-behavior. What is the heap? Free unused mem is called heap

What is the Difference between calloc and malloc? malloc: allocate calloc: allocate m times n bytes initialized to 0 n bytes

What is the difference between the functions rand(),random(),srand() and randomize()? RAND: Rand uses a multiplicative congruential random number generator with period232 to returnsuccessive pseudo-random numbers in the range 0 to RAND_MAX. Return Value: Rand returns the generated pseudo-random number. RANDOM(): Random returns a random number between 0 and (num1).random(num) is a macro defined in STDLIB.H.

RANDOMIZE(): Randomize initializes the random number generator with a random value. Because randomize is implemented as a macro that calls the time function prototyped in TIME.H, you should include TIME.H when you

use

this

routine

SRAND(): The random number generator is reinitialized by calling srand with an argument value of 1.Thegenerator can be set to a new starting point by calling srand with a given seed number.

Differentiate between a linker and linkage? A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable WRITE C PROGRAMME TO CREATE A FILE AND READ A FILE. What is indirection?

If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value. What is the quickest sorting method to use ? What is Preprocessor? preprocessor is a program which processes our source program before it goes to the compiler for compilation. What is hashing? The process of mapping the large amount of data in to the smaller table is called as hashing

Programs

Q: In C, explain the difference between the & operator and the * operator. A: & is the address operator, and it creates pointer values. * is the indirection operator, and it dereferences pointers to access the object pointed to. Example: In the following example, the pointer ip is assigned the address of variable i (&i). After that assignment, the expression *ip refers to the same object denoted by i: int i, j, *ip; ip = &i; i = 22; j = *ip; /* j now has the value 22 */ *ip = 17; /* i now has the value 17 */ (Back) Q: Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom"). A: /* BEGIN C SNIPET */ #include <string.h> void is_palindrome ( char *in_str ) { char *tmp_str; int i, length; length = strlen ( *in_str ); for ( i = 0; i < length; i++ ) { *tmp_str[length-i-1] = *in_str[i]; } if ( 0 == strcmp ( *tmp_str, *in_str ) ) printf ("String is a palindrome"); else printf ("String is not a palindrome"); }

/* END C SNIPET */ Q: Write the code to sort an array of integers. A: /* BEGIN C SNIPET */ void bubblesort (int x[], int lim) { int i, j, temp; for (i = 0; i < lim; i++) { for (j = 0; j < lim-1-i; j++) { if (x[j] > x[j+1]) { temp = x[j]; x[j] = x[j+1]; x[j+1] = temp; } /* end if */ } /* end for j */ } /* end for i */ } /* end bubblesort */ /* END C SNIPET */ Some optimizations that can be made are that a single-element array does not need to be sorted; therefore, the "for i" loop only needs to go from 0 to lim-1. Next, if at some point during the iterations, we go through the entire array WITHOUT performing a swap, the complete array has been sorted, and we do not need to continue. We can watch for this by adding a variable to keep track of whether we have performed a swap on this iteration. (Back)

Programming Answer 5 Q: Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom"). A:

/* BEGIN C SNIPET */ #include <string.h> void is_palindrome ( char *in_str ) { char *tmp_str; int i, length; length = strlen ( *in_str ); for ( i = 0; i < length; i++ ) { *tmp_str[length-i-1] = *in_str[i]; } if ( 0 == strcmp ( *tmp_str, *in_str ) ) printf ("String is a palindrome"); else printf ("String is not a palindrome"); } /* END C SNIPET */ (Back) Q: In C, explain the difference between the & operator and the * operator. A: & is the address operator, and it creates pointer values. * is the indirection operator, and it dereferences pointers to access the object pointed to. Example: In the following example, the pointer ip is assigned the address of variable i (&i). After that assignment, the expression *ip refers to the same object denoted by i: int i, j, *ip; ip = &i; i = 22; j = *ip; /* j now has the value 22 */ *ip = 17; /* i now has the value 17 */ (Back)

Q: Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom"). A: /* BEGIN C SNIPET */ #include <string.h> void is_palindrome ( char *in_str ) { char *tmp_str; int i, length; length = strlen ( *in_str ); for ( i = 0; i < length; i++ ) { *tmp_str[length-i-1] = *in_str[i]; } if ( 0 == strcmp ( *tmp_str, *in_str ) ) printf ("String is a palindrome"); else printf ("String is not a palindrome"); } /* END C SNIPET */ Q: Write the code to sort an array of integers. A: /* BEGIN C SNIPET */ void bubblesort (int x[], int lim) { int i, j, temp; for (i = 0; i < lim; i++) { for (j = 0; j < lim-1-i; j++) { if (x[j] > x[j+1]) { temp = x[j]; x[j] = x[j+1]; x[j+1] = temp; } /* end if } /* end for j } /* end for i */ */ */

/* end bubblesort */

/* END C SNIPET */ Some optimizations that can be made are that a single-element array does not need to be sorted; therefore, the "for i" loop only needs to go from 0 to lim-1. Next, if at some point during the iterations, we go through the entire array WITHOUT performing a swap, the complete array has been sorted, and we do not need to continue. We can watch for this by adding a variable to keep track of whether we have performed a swap on this iteration. (Back)

Programming Answer 5 Q: Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom"). A: /* BEGIN C SNIPET */ #include <string.h> void is_palindrome ( char *in_str ) { char *tmp_str; int i, length; length = strlen ( *in_str ); for ( i = 0; i < length; i++ ) { *tmp_str[length-i-1] = *in_str[i]; } if ( 0 == strcmp ( *tmp_str, *in_str ) ) printf ("String is a palindrome"); else printf ("String is not a palindrome"); } /* END C SNIPET */ (Back)

Anda mungkin juga menyukai