Vous êtes sur la page 1sur 9

1. What is a programming language? A programming language is a formal language designed to communicate instructions to a machine, particularly a computer.

Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely. 2. What are the various levels of programming language? machine languages; a computer programming language consisting of binary or hexadecimal instructions which a computer can respond to directly. assembly languages; An assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generallyone-to-one) correspondence between the language and the architecture's machine code instructions

high-level languages. a problem-oriented language requiring little knowledge of the computer on which it will be run

3. What do you meant by Compilation & Interpretation? In a compiled implementation of a language, a compiler will translate the program directly into code that is specific to the target machine, which is also known as machine code In an interpreted implementation of a language, the source code is not directly run by the target machine. What happens instead is that another program reads and then executes the original source code. This other program is also known as the interpreter. The interpreter is usually written specifically for the native machine. 4. What is an Object Code? Object code, or sometimes object module, is what a computer compiler produces.[1] In a general sense object code is a sequence of statements or instructions in a computer language,[2]usually a machine code language (i.e., 1's and 0's) or an intermediate language such as RTL. 5. Write a simple C program and explain all its context. 6. What is a Header File? And why we need them? In computer programming, a header file is a file that allows programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. Including a header file is equal to copying the content of the header file but we do not do it because it will be very much error-prone and it is not a good idea to copy the content of header file in the source files, specially if we have multiple source file comprising our program.

7. How to create your own Header File?


Save Code with [.h ] Extension . Let name of our header file be myhead [ myhead.h ] Compile Code if required.

8. In how many ways can you include Header Files? 9. What do you meant by pre-processor directive? In computer programming, a directive or pragma (from "pragmatic") is a language construct that specifies how a compiler (or assembler or interpreter) should process its input. Directives are not part of the language proper they are not part of the grammar, and may vary from compiler to compiler but instead function either as an in-band form of a command-line option, specifying compiler behavior, or are processed by a preprocessor. In some cases directives specify global behavior, while in other cases they only affect a local section, such as a block of programming code. 10. Explain the execution flow of a simple C program. 11. What is a Return Type for? In computer programming, the return type (or result type) defines and constrains the data type of the value returned from a subroutine or method.[1] In many programming languages (especially statically-typed programming languages such as C, C++, Java) the return type must be explicitly specified when declaring a function. 12. What is an Identifier? identifiers:- identifiers r names given to program elements such as variables , arrays & functions. Basically identifers r the sequences of alphabets or digits. Rules for forming identifier name * the first character must be an alphabet (uppercase or lowercase) or an underscore * all succeeding characters must be letters or digits. * No special characters or punctuation symbols are allowed except the underscore"_". * No two successive underscores are allowed. * Keywords shouldnt be used as identifiers 13. Name few Keywords. Auto, break, case, const, enum, extern, float 14. What is an Escape Sequence? Name few and its purpose.

Escape sequences are used in the programming languages C and C++, and also in many more languages (with some variations) like Java and C#. These are character combinations that comprise a backslash (\) followed by some character. They give results such as getting to the next line or a tab space. \n-new line; \b-backspace; \a-beep

15. What would a printf() function returns? int. On success, the total number of characters written is returned. On failure, a negative number is returned. 16. What would a scanf() function returns? On success, the function returns the number of items successfully read. This count can match the expected number of readings or fewer, even zero, if a matching failure happen 17. What do you meant by primitives? It is a data type provided by a language implicitly (Others are user defined classes) For example, in languages like C and C++, you have a number of built-in scalar types int, float, double, char, etc. These are "primitive" in the sense that they cannot be decomposed into simpler components. From these basic types you can define new types - pointer types, array types, struct types, union types, etc. 18. What is a Function? A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed from as many different points in a C Program as required. 19. Explain Function Declaration and Function Definition. Func dec: A function prototype or function interface in C, Perl, PHP or C++ is a declaration of a function that omits the function body but does specify the function's return type, name, arity and argument types. While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface. Func def: nothing but the actual function 20. What do you meant by Formal & Actual arguments? The arguments passed to the functions while the function is called is known as the actual arguments, whereas the arguments declared in the function header is called as formal arguments

21. What are Storage Classes? A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program. There are following storage classes which can be used in a C Program

auto register static extern

22. Which Storage class is used to call function written in another C program file? The static storage class specifier lets you define objects or functions with internal linkage, which means that each instance of a particular identifier represents the same object or function within one file only. In addition, objects declared static have static storage duration, which means that memory for these objects is allocated when the program begins running and is freed when the program terminates. 23. Which is the Default Storage class? When you apply the keyword static to a variable defined in namespace scope it does not affect itsstorage duration - it was static already and it remains static - but it affects it linkage. The keywordstatic changes the linkage of such variable from external (default) to internal

24. Define Function call and what happens when a function is called? a call that passes control to a subroutine; after the subroutine is executed control returns to the next instruction in main program Some implementations will put all the arguments on the stack, some will use registers, and many use a mix 25. What do you meant by NULL? NULL is a built in constant which has a value of 0. It is also the same as the character '\0' used to terminate strings in C Null can also be the value of a pointer which is really the same as 0 unless the CPU supports a special bit pattern for a null pointer. 26. Define MACRO. A macro is a name given to a block of C statements as a pre-processor directive. Being a pre-processor, the block of code is communicated to the compiler before entering into the actual coding (main () function). A macro is defined with the preprocessor directive, #define. 27. Disadvantage of MACRO The disadvantage of the macro is the size of the program. The reason is, the pre-processor will replace all the macros in the program by its real definition prior to the compilation process of the program. 28. What is a Pointer? A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.

29. What are all the Indirection operators in C? The indirection operator (*) accesses a value indirectly, through a pointer. The operand must be a pointer value. The result of the operation is the value addressed by the operand; that is, the value at the address to which its operand points. The type of the result is the type that the operand addresses.

30. Difference between Call -by-value & Call-by-Reference. If data is passed by value, the data is copied from the variable used in for example main() to a variable used by the function. So if the data passed (that is stored in the function variable) is modified inside the function, the value is only changed in the variable used inside the function If data is passed by reference, a pointer to the data is copied instead of the actual variable as is done in a call by value. Because a pointer is copied, if the value at that pointers address is changed in the function, the value is also changed in main(). 31. Discuss Array. C programming language provides a data structure called the array, which can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. 32. How to use an array as pointer. double *p; double balance[10]; p = balance; 33. Discuss post increment & pre increment. ++x is pre-increment and x++ is post-increment that is in the first x is incremented before being used and in the second x is incremented after being used. 34. What do you meant by Void Pointer? A void pointer is pointer which has no specified data type. The keyword void is preceded the pointer variable, because the data type is not specific. It is also known as a generic pointer. The void pointer can be pointed to any type. If needed, the type can be casted. 35. Write some code to Dynamically assign memory for pointer. #include <stdio.h> #include <string.h> #include <stdlib.h> int main() {

char *mem_allocation; /* memory is allocated dynamically */ mem_allocation = malloc( 20 * sizeof(char) ); if( mem_allocation== NULL ) { printf("Couldn't able to allocate requested memory\n"); } else { strcpy( mem_allocation,"fresh2refresh.com"); } printf("Dynamically allocated memory content : " \ "%s\n", mem_allocation ); free(mem_allocation); }

36. Difference between malloc , calloc & realloc. First of all realloc() is actually a reallocation function. It is used to resize a previously allocated (using malloc(), calloc(), or realloc()) block of memory to the desired size. Depending on whether the new size if less or more than the original size the block may be moved to new location. malloc() allocates memory in bytes. So the programmer specifies how many bytes of memory malloc should allocate and malloc will allocate that many bytes (if possible) and return the address of the newly allocated chunk of memory. malloc() does not initialize memory after it allocates it. It just returns the pointer back to the calling code and the calling code is responsible for initialization or resetting of the memory, most probably by using the memset() function. On the other hand calloc() initializes the allocated memory to 0. calloc() is obviously slower than malloc() since it has the overhead of initialization, so it may not be the best way to allocate memory if you don't care about initializing the allocated memory to 0. 37. What is a double pointer? Pointer stores the address of the variable and double pointer store the address of pointer variable. 38. What do you meant by type casting? Typecasting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make 'a' function as a char. 39. What is a Structure? And why we need it? When programming, it is often convenient to have a single name with which to refer to a group of a related values. Structures provide a way of storing many different values in variables of potentially different types under the same name. This makes it a more modular program, which is easier to modify because its design makes things more compact. Structs are generally useful whenever a lot of data needs to be grouped

together--for instance, they can be used to hold records from a database or to store information about contacts in an address book.

40. How to access member variables using structure pointer? Arrow operator is used. 41. Explain typedef. typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to form complex types from more-basic machine types[1] and assign simpler names to such combinations. They are most often used when a standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another 42. What do you meant by memory leak? A memory leak is like a virtual oil leak in your computer. It slowly drains the available memory, reducing the amount of free memory the system can use. Most memory leaks are caused by a program that unintentionally uses up increasing amounts of memory while it is running. This is typically a gradual process that gets worse as the program remains open.

43. What is a Union? To define a union, you must use the union statement in very similar was as you did while defining structure. The union statement defines a new data type, with more than one member for your program. 44. Difference between Structure & Union. Structure Union i. Access Members We can access all the members of structure at Only one member of union can be accessed at anytime. anytime. ii. Memory Allocation Allocates memory for variable which variable require more Memory is allocated for all variables. memory. iii. Initialization All members of structure can be initialized Only the first member of a union can be initialized. iv. Keyword 'struct' keyword is used to declare structure. 'union' keyword is used to declare union. v. Syntax struct struct_name union union_name { { structure element 1; union element 1; structure element 2; union element 2; ------------------------------------structure element n; union element n; }struct_var_nm; }union_var_nm; vi. Example union item_mst { int rno;

struct item_mst { int rno;

char nm[50]; }it; }it;

char nm[50];

45. Give example. Where we use union. 46. Explain feof(). Checks whether the end-of-File indicator associated with stream is set, returning a value different from zero if it is. This indicator is generally set by a previous operation on the stream that attempted to read at or past the end-of-file. 47. Discuss r+,w+ & a+ modes of File Operation. r Read-only mode. The file pointer is placed at the beginning of the file. This is the default mode. r+ Read-write mode. The file pointer will be at the beginning of the file. w Write-only mode. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. w+ Read-write mode. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing. a Write-only mode. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing. a+ Read and write mode. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing. 48. What is an enum? Short for enumeration, an enum variable type can be found in C (Ansi, not the original K&R),C++ and C#. The idea is that instead of using an int to represent a set of values, a type with a restricted set of values in used instead. 49. How can you assign user specified constant to enum variables? 50. How to free a dynamically allocated memory? Free() function

Vous aimerez peut-être aussi