Introduction to Computing with C PDF

Summary

This document provides an introductory overview of computing concepts, focusing on programming with C. The document includes questions and answers for a variety of core topics.

Full Transcript

Introduc)on to Compu)ng & Programming with C Objec&ve type: 1X50=50 1. UNIVAC is………… Ans: Universal Automatic Computer 2. The brain of any computer system is ………….. Ans: CPU 3. The two kinds of main memory are……… Ans: Prim...

Introduc)on to Compu)ng & Programming with C Objec&ve type: 1X50=50 1. UNIVAC is………… Ans: Universal Automatic Computer 2. The brain of any computer system is ………….. Ans: CPU 3. The two kinds of main memory are……… Ans: Primary and Secondary 4. Computer is free from tiresome and boardroom, which is called……….. Ans: Diligence 5. Chief component of first generation computer was……….. Ans: Vacuum Tubes and Valves 6. What are the hardware components in computer? Ans: CPU, Motherboard, keyboard, mouse, speaker. 7. Write the different types of memory in computing. Ans: Two types of computer memory: primary and secondary 8. What is internet? Ans: A network of networks in which users at any one computer can perform any task. 9. Write the various types of programming language. Ans: C, C++, Java, Python 10. What are the characteristics of a computer? Ans: Speed, Accuracy, Diligence, Reliability, Memory, Logical, Versatility. 11. List out any two kinds of operating system. Ans: Windows, Unix, Linux 12. State the components of digital computer. Ans: (1) input-output equipment, (2) main memory, (3) control unit, and (4) arithmetic-logic unit 13. Write Short notes on Function of Operating System. Ans: Manages files, manages memory, manages processes, handles input and output, and controls peripheral devices like disk drives and printers, among other things 14. List out the types of memory units. Ans: Bit, Nibble, Byte, Kilobyte, Megabyte, Gigabyte, Terabyte & Petabyte 15. Expand MICR and OCR in your language. Ans: OCR stands for Optical Character Recognition/Reader. MICR stands for Magnetic Ink Character Recognition/Reader 16. What are the components of CPU? Ans: A CPU has three main parts: arithmatic logic unit (ALU), control unit (CU), and memory unit 17. What is e-mail? Ans: “email,” is a communication method that uses electronic devices to deliver messages across computer networks 18. Name the various kinds of Software. Ans: Application software, System software, Driver software, Middleware & Programming software. 19. What is pseudocode? Ans: In computer science, pseudocode is a description of the steps in an algorithm using a mix of conventions of programming languages with informal, usually self- explanatory, notation of actions and conditions. 20. Define flowchart. Ans: A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be defined as a diagrammatic representation of an algorithm, a step- by-step approach to solving a task. 21. What is Token in C? Ans: A token is a sequence of characters that represents a specific element in the program, such as a keyword, variable, operator, or punctuation symbol. C language has six types of tokens: keywords, identifiers, constants, operators, special symbols, and strings. 22. What is variable in C? Ans: Variable is basically nothing but the name of a memory location that we use for storing data. 23. What is an operator in C? Ans: The operators are types of symbols that inform a compiler for performing some specific logical or mathematical functions. 24. What are basic data types available in C? Ans: char, int, float and double 25. What is an array in C? Ans: An array in C is the collection of similar data items together in a contiguous memory location. 26. What is string in C? Ans: A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '\0 27. What is a pointer in C? Ans: The pointers in C language refer to the variables that hold the addresses of different variables of similar data types. We use pointers to access the memory of the said variable and then manipulate their addresses in a program. 28. What is preprocessor directive in C? Ans: Preprocessor directives are lines of the source file where the first non-whitespace character is #, which distinguishes them from other lines of text. 29. What is a nested loop in C? Ans: C supports nesting of loops in C. Nesting of loops is the feature in C that allows the looping of statements inside another loop. 30. What is format specifier in C? Ans: Format specifiers in C are used to take inputs and print the output of a type. The symbol we use in every format specifier is %. 31. What is recursion in C? Ans: The recursion process in C refers to the process in which the program repeats a certain section of code in a similar way. 32. What is meant by call-by value in C? Ans: In this parameter passing method, values of actual parameters are copied to function's formal parameters and the two types of parameters are stored in different memory locations. So any changes made inside functions are not reflected in actual parameters of caller. 33. What is meant by call-by reference in C? Ans: Call by reference method copies the address of an argument into the formal parameter. In this method, the address is used to access the actual argument used in the function call. It means that changes made in the parameter alter the passing argument. 34. Define Union in C. Ans: Union is a user defined datatype in C programming language. It is a collection of variables of different datatypes in the same memory location. 35. What is a computer program? Ans: A computer program is a sequence or set of instructions in a programming language for a computer to execute. It is one component of software. 36. What is an ALU? Ans: An arithmetic logic unit (ALU) is a key component of a computer's central processor unit. The ALU performs all arithmetic and logic operations that must be performed on instruction words. 37. What are registers? Ans: Registers are a type of computer memory used to quickly accept, store, and transfer data and instructions that are being used immediately by the CPU. 38. What is a volatile memory? Ans: Volatile memory is a type of memory that maintains its data only while the device is powered. If the power is interrupted for any reason, the data is lost. 39. What is a non-volatile memory? Ans: Non-volatile memory (NVM) or non-volatile storage is a type of computer memory that can retain stored information even after power is removed. 40. What are keywords in C? Ans: Keywords in C are words that have a specific and pre-defined purpose. There are 32 keywords in C that must be used for specific contexts. It is important to understand keywords to write efficient code. 41. What is type casting in C? Ans: Type casting refers to changing a variable of one data type into another. The compiler will automatically change one type of data into another if it makes sense. For instance, if you assign an integer value to a floating-point variable, the compiler will convert the int to a float. 42. What are * and & operators means? Ans: The '&' or address operator, is a unary operator that returns the address of its operand. The '*' operator, commonly referred as indirection operator, returns the value of the object to which its operand (a pointer) points. 43. What are storage classes? Ans: Storage class in the C language defines the location, lifetime and other specific attributes of a variable. Knowledge of the storage class is important in accessing a block of code. 44. A byte consists of ………… Ans: eight bits 45. RAM is divided into two types_______ and ____________. Ans: DRAM and SRAM 46. ASCII stands for _________ Ans: American Standard Code for Information Interchange. 47. ENIAC stands for ______________ Ans: Electronic Numerical Integrator and Computer. 48. The binary language consists of two digits: _________ and ____________. Ans: 0 and 1 49. ____________ is the science that attempts to create machines that will emulate the human thought process. Ans: AI 50. ____________are the fastest and most expensive computers. Ans: Supercomputers Subjec(ve type: 5 marks each Q1. Explain the different types of computer. Computers can be classified into several categories based on their size, purpose, and processing power. The main types include: 1. Supercomputers : These are the most powerful computers, used for complex calcula?ons and simula?ons, such as weather forecas?ng and scien?fic research. They can process vast amounts of data at incredible speeds. 2. Mainframe Computers : These are large and powerful systems primarily used by organiza?ons for bulk data processing and cri?cal applica?ons. They support mul?ple users and are known for their reliability and security. 3. Minicomputers : Also known as mid-range computers, these are smaller than mainframes but larger than personal computers. They serve mul?ple users simultaneously and are oCen used in manufacturing and research environments. 4. Personal Computers (PCs) : These are designed for individual use, available in various forms such as desktops, laptops, and tablets. They are versa?le and used for a wide range of applica?ons from office work to gaming. 5. WorkstaBons : High-performance computers designed for technical or scien?fic applica?ons. They have more powerful processors and higher memory capaci?es compared to standard PCs. 6. Embedded Systems : These are specialized compu?ng systems that perform dedicated func?ons within larger systems, such as in automobiles, appliances, or industrial machines. Q2. Describe the different types of so 0) { prin?("Posi2ve"); } else if(num < 0) { prin?("Nega2ve"); } else { prin?("Zero"); } Q7. Explain the different types of loops in C with syntax. 1. for Loop Syntax : for(ini?aliza?on; condi?on; increment/decrement) { // loop body } 2. while Loop Syntax : while(condi?on) { // loop body } 3. do-while Loop Syntax : do { // loop body } while(condi?on); Example : for(int i = 0; i < 5; i++) { prinM("%d\n", i); } Q8. What are the key features in C programming language? C programming language is known for its features: 1. Efficiency: Provides low-level access to memory. 2. Portability: Programs can be compiled on different machines with minimal changes. 3. Rich Library Support: Extensive built-in func?ons. 4. Structured Language: Encourages modular programming through func?ons. 5. Flexibility with Pointers: Allows direct memory manipula?on. Q9. MenPon the difference between structure and union with example. Example : struct Person { char name; int age; }; union Data { int intValue; float floatValue; }; Q10. Define flowchart. Explain with an example. A flowchart is a visual representa?on of a process or algorithm, using symbols like arrows, ovals, rectangles, and diamonds to denote different types of ac?ons or steps. Example Flowchart Steps : 1. Start/End represented by ovals. 2. Process steps represented by rectangles. 3. Decision points represented by diamonds. Q11. Write an algorithm to find the area and perimeter of a circle. To find the area and perimeter of a circle: 1. Start. 2. Input radius $$ r $$. 3. Calculate area using $$ \text{Area} = \pi r^2 $$. 4. Calculate perimeter using $$ \text{Perimeter} = 2\pi r $$. 5. Output area and perimeter. 6. End. Q12. Explain funcPon call, funcPon definiPon and funcPon prototype with examples. 1. FuncBon Prototype : Declara?on of func?on before its use. int add(int a, int b); 2. FuncBon DefiniBon : Implementa?on of the func?on. int add(int a, int b) { return a + b; } 3. FuncBon Call : Invoking the func?on. int result = add(5, 10); Q13. What are input devices? MenPon and explain any two input devices. Input devices allow users to enter data into a computer system. 1. Keyboard : A primary input device used for typing text and commands. 2. Mouse : A poin?ng device used to interact with graphical elements on the screen. Q14. What is variable? List the restricPons on variable names. A variable is a named storage loca?on in memory that holds data which can change during program execu?on. Restric?ons on Variable Names: 1. Must begin with a lerer or underscore. 2. Can contain lerers, digits, or underscores. 3. Cannot use keywords as names. 4. Case-sensi?ve. Q15. What are basic data types available in ‘C’ language? Write the significance of each data type. Q16. DisPnguish between hardware and so 0) { prinM("str1 is greater than str2\n"); } else { prinM("str1 is less than str2\n"); } return 0; } Summary: Arrays are used to store mul?ple values of the same type. A string is a special kind of array, specifically an array of characters ending with \0. The string manipula?on func?ons like strlen(), strcpy(), strcat(), and strcmp() allow us to perform common opera?ons on strings such as measuring length, copying, concatena?ng, and comparing. Q13. Give the scope and lifePme of the following: 1. External variable 2. StaPc variable 3. AutomaPc variable 4. Register variable What is a preprocessor direcPve? Explain #define and #include preprocessor direcPves. (8+7) Ans. 1. Scope and LifeBme of Different Types of Variables (i) External Variable: Scope : An external variable is declared outside of all func?ons, typically at the beginning of the program. It has global scope, meaning it can be accessed by any func?on in the program aCer it has been declared. LifeBme : The life?me of an external variable is the dura?on of the en?re program. It is created when the program starts and destroyed when the program terminates. Example: #include int external_var = 10; // External variable void funcBon1() { prinp("External variable in funcBon1: %d\n", external_var); } int main() { prinp("External variable in main: %d\n", external_var); funcBon1(); return 0; } (ii) StaBc Variable : Scope : A sta?c variable has local scope if declared inside a func?on. However, unlike automa?c variables, it retains its value between func?on calls. It cannot be accessed outside the func?on it is declared in. LifeBme : The life?me of a sta?c variable is the dura?on of the program. It is ini?alized only once and retains its value throughout the program's execu?on, even between func?on calls. Example : #include void sta?c_example() { sta?c int count = 0; // Sta?c variable count++; prinM("Sta?c count: %d\n", count); } int main() { sta?c_example(); sta?c_example(); sta?c_example(); return 0; } (iii) AutomaBc Variable : Scope : An automa?c variable is the default variable type inside func?ons. It has local scope within the func?on where it is declared. It cannot be accessed outside the func?on. LifeBme : The life?me of an automa?c variable is the dura?on of the func?on's execu?on. It is created when the func?on is called and destroyed when the func?on exits. Example: #include void automa?c_example() { int auto_var = 10; // Automa?c variable prinM("Automa?c variable: %d\n", auto_var); } int main() { automa?c_example(); return 0; } (iv) Register Variable : Scope : A register variable has local scope and is typically declared inside func?ons. However, it is stored in a processor register, making it faster than regular automa?c variables. LifeBme : The life?me of a register variable is the dura?on of the func?on's execu?on, similar to automa?c variables. Example : #include void register_example() { register int count = 0; // Register variable for (count = 0; count < 5; count++) { prinM("Count: %d\n", count); } } int main() { register_example(); return 0; } 2. Preprocessor DirecBves A preprocessor direc?ve is a command in C that is processed before the actual compila?on of the program begins. Preprocessor direc?ves allow for including files, defining constants, and performing condi?onal compila?on, among other things. i) #define DirecBve The # define direc?ve is used to define constants or macros that will be replaced by the preprocessor before the compila?on starts. Syntax : #define constant_name value Example : #include #define PI 3.14159 int main() { prinM("Value of PI: %f\n", PI); return 0; } ExplanaBon : The # define direc?ve defines PI as 3.14159. Whenever PI is used in the program, it will be replaced with 3.14159 before compila?on. ii) #include DirecBve The #include direc?ve is used to include header files in the program. It allows access to func?ons and constants defined in external libraries. Syntax : #include Example : #include int main() { prinM("Hello, World!\n"); return 0; } ExplanaBon : The #include direc?ve includes the standard input-output library, allowing us to use func?ons like prinp(). Summary : External variables have global scope and program life?me. Sta?c variables have local scope but program life?me. Automa?c variables have local scope and func?on life?me. Register variables are stored in CPU registers for fast access but have local scope and func?on life?me. Preprocessor direc?ves (#define and #include) are commands that modify the program before compila?on begins. #define is used for constants/macros, and #include is used to include header files. Q14. What are the advantages and disadvantages of using pointers in C? Define null pointer and void. Write a C program to calculate the factorial of a given number. (5+5+5) Ans. 1. Advantages and Disadvantages of Using Pointers in C Advantages of Using Pointers : 1. Efficient Memory Management: o Pointers allow you to directly access memory loca?ons, which can lead to more efficient use of memory. This is especially useful when working with large data structures like arrays or matrices. 2. Dynamic Memory AllocaBon : o Pointers enable dynamic memory alloca?on, allowing programs to request and free memory during run?me using func?ons like malloc(), calloc(), and free(). 3. Passing Large Data to FuncBons : o Instead of passing large data (like arrays or structs) by value, you can pass their memory addresses (using pointers), which is more efficient and avoids the overhead of copying large amounts of data. 4. Accessing Hardware/Low-Level OperaBons : o Pointers can be used to directly interact with hardware, perform system-level programming, or manipulate memory addresses, which is essen?al for certain applica?ons like device drivers or embedded systems. 5. Increased Flexibility : o Pointers allow for more flexible data structures, such as linked lists, trees, and graphs, that can dynamically grow and shrink during run?me. Disadvantages of Using Pointers : 1. Complexity: o Pointers can make programs more complex, leading to difficult-to-debug code. A small mistake, such as dereferencing an unini?alized or null pointer, can lead to crashes or undefined behavior. 2. Memory Leaks : o Improper management of dynamically allocated memory can lead to memory leaks. This happens when memory is allocated but never freed, resul?ng in wasted resources. 3. Security Issues: o Since pointers can be manipulated directly, improper use of pointers can result in security vulnerabili?es, such as buffer overflow aracks or memory corrup?on. 4. Risk of Undefined Behavior : o Incorrect pointer arithme?c or dereferencing invalid pointers can lead to undefined behavior, including program crashes, data corrup?on, or security vulnerabili?es. 2. DefiniBon of Null Pointer and Void Pointer Null Pointer : A null pointer is a pointer that does not point to any valid memory loca?on. It is oCen used to represent an unini?alized pointer or to indicate that a pointer is not currently poin?ng to any object. Syntax: int *ptr = NULL; // Null pointer Example : #include int main() { int *ptr = NULL; // Null pointer if (ptr == NULL) { prinM("Pointer is null\n"); } return 0; } Void Pointer : A void pointer is a pointer that can point to any data type. It is a generic pointer and does not have a specific type associated with it. To dereference a void pointer, it must first be cast to another pointer type. Syntax: void *ptr; Example: #include int main() { int num = 10; void *ptr = &num; // Void pointer poin?ng to an integer // Typecas?ng void pointer to int pointer to dereference prinM("Value: %d\n", *(int *)ptr); return 0; } 3. C Program to Calculate the Factorial of a Given Number A factorial of a number n is the product of all posi?ve integers less than or equal to n. Factorial Program Using Recursion : #include // Func?on to calculate factorial using recursion int factorial(int n) { if (n == 0 || n == 1) { return 1; // Base case } else { return n * factorial(n - 1); // Recursive call } } int main() { int num; prinM("Enter a number to calculate its factorial: "); scanf("%d", &num); // Validate input if (num < 0) { prinM("Factorial is not defined for nega?ve numbers.\n"); } else { int result = factorial(num); prinM("Factorial of %d is %d\n", num, result); } return 0; } Summary: Advantages of pointers include efficient memory management, dynamic memory alloca?on, passing large data to func?ons, and increased flexibility in data structures. Disadvantages of pointers include complexity, memory leaks, security issues, and poten?al undefined behavior. A null pointer points to no valid memory loca?on, and a void pointer can point to any data type. The factorial program demonstrates the use of recursion to calculate the factorial of a given number. Q15. Write a C program to make a palern like a pyramid, where n is taken from the user as input. * * * * * * * * * * * * * * * What is switch case in C? Explain with an example. (10+5) Ans. 1. Code: #include int main() { int n, i, j; // Asking user for input prinM("Enter the number of rows for the pyramid: "); scanf("%d", &n); // Outer loop to handle the number of rows (n) for(i = 1; i

Use Quizgecko on...
Browser
Browser