Programming in C Practical Viva Questions PDF

Document Details

AuthenticSerpentine5959

Uploaded by AuthenticSerpentine5959

Shri Mathuradas Mohota College of Science, Nagpur

Tags

C programming programming questions programming viva computer science

Summary

This document contains a set of questions about programming in C. The questions cover basic concepts like operators, data types, loops, and arrays. It's a helpful resource for testing knowledge and preparing for practical exams or vivas.

Full Transcript

# C Programming Language ## Basics 1. **Which type of language is C?** - C is a high-level language and general-purpose structured programming language. 2. **What is a compiler?** - A compiler is a software program that translates programs developed in a high-level language into executable...

# C Programming Language ## Basics 1. **Which type of language is C?** - C is a high-level language and general-purpose structured programming language. 2. **What is a compiler?** - A compiler is a software program that translates programs developed in a high-level language into executable object code. 3. **What is an algorithm?** - An algorithm is the approach or method used to solve a problem. 4. **What is a C token and types of C tokens?** - The smallest individual units are known as C tokens. - C has six types of tokens: - Keywords - Constants - Identifiers - Strings - Operators - Special symbols. 5. **How many Keywords (reserve words) are in C?** - There are 32 Keywords in the C language. 6. **What is an identifier?** - Identifiers are user-defined names given to variables, functions, and arrays. 7. **What are the Back Slash character constants or Escape sequence characters available in C?** - Back Slash character constants are: - `\t` - `\n` - `\0` 8. **What is a variable?** - Variables are user-defined names given to memory locations and are used to store values. - A variable may have different values at different times during program execution. 9. **What are the Data Types present in C?** - C has three main categories of data types: - **Primary or Fundamental Data types:** `int`, `float`, `char` - **Derived Datatypes:** arrays, pointers - **User-Defined data types:** structures, unions, enum 10. **How to declare a variable?** - The syntax for declaring a variable is: `data_type variable_name-1, variable_name-2,....variable_name-n;` - For example: - `int a, b;` - `float p,q;` 11. **What is meant by initialization and how do we initialize a variable?** - Assigning a value to a variable while declaring it is known as initialization. - Variables can be initialized using the assignment operator (=). ## Operators 12. **How many types of operators are there in C?** - C has several operator types: - **Arithmetic Operators:** +, -, *, /, % - **Relational Operators:** <, <=, >, >=, != - **Logical Operators:** &&, ||, ! - **Assignment Operators:** =, +=, -=, *=, /= - **Increment and Decrement Operators:** ++, -- - **Conditional Operator:** ?: - **Bitwise Operators:** <<, >>, ~, &, |, ^ - **Special Operators:** ., ->, &, *, sizeof 13. **What is a Unary operator and what are the unary operators present in C?** - A unary operator takes only one operand. - C has several unary operators: - Unary plus (+) - Unary minus (-) - Increment and Decrement operators (++,-) - Address of operator (&) - Value at operator (*) - sizeof operator - ones complement operator (~) 14. **What is the use of the modulus (%) operator?** - The modulus operator calculates the remainder of an integer division. - It cannot be used on floating-point data. 15. **What is the use of `printf` and `scanf` functions in C?** - `printf` is used to display values of variables and results of expressions on the screen. - `scanf` is used to accept values from the keyboard and store them in variables. ## Control Flow 16. **Forms of IF statements?** - Common forms of `if` statements in C include: - Simple `if` statement - `if-else` statement - `nested if-else` statement - `else if` ladder 17. **What is a `goto` statement?** - `goto` is an unconditional branching statement that transfers control to a specific label. 18. **What is a loop?** - A loop is a sequence of statements that runs repeatedly. 19. **What are loop control statements in C?** - Common loop control statements in C include: - `while` - `do-while` - `for` 20. **What are sections present in `for` loop?** - A `for` loop has three sections: - Initialization - Conditional - Increment/Decrement 21. **What is the use of `break` statements?** - `break` statements are used to exit from a loop. ## Arrays and Pointers 22. **What is an array?** - An array is a collection of similar elements. 23. **How can we initialize an array?** - An array can be initialized by using a comma-separated list of constant expressions enclosed in braces (`{}`). - The initializer is preceded by an equal sign (=). - You do not need to initialize all elements in an array. 24. **What is the difference between a normal variable and an array variable?** - A normal variable can store only one value at a time. - An array variable can store several values at a time. 25. **What are the types of Arrays?** - Arrays come in different dimensions: - One-Dimensional array - Two-Dimensional array - Multi-Dimensional array 26. **What is a character array?** - A character array is an array designed to store multiple characters. 27. **What is a function?** - A function is a self-contained block of statements used to perform a specific task and simplify code. 28. **What are the types of functions?** - C functions are divided into two main categories: - User-defined functions - Built-in functions 29. **Which are called built-in functions?** - Built-in functions are pre-defined functions designed to perform specific operations like: - `printf`, `scanf`, `clrscr`, `gotoxy`, `string handling`, `file handling`. 30. **What is a recursive function?** - A recursive function is a function that calls itself. 31. **How to pass an array to a function?** - Arrays are passed to functions by sending their addresses. 32. **What is a pointer variable?** - A pointer variable is a variable that can store the address of another variable. 33. **How can we store the address of a variable in a pointer?** - The `&` operator (address of operator) is used to store the address of a variable. 34. **How many bytes does a pointer variable occupy in memory?** - A pointer variable occupies two bytes in memory, regardless of its data type. ## Storage Classes 35. **What are storage classes available in C?** - The four main storage classes in C are: - `auto` - `static ` - `extern` - `register` 36. **What is a structure?** - A structure is a user-defined data type that groups dissimilar elements together. It provides a way to manage data of different types as a single unit. 37. **How to access structure members?** - Structure members can be accessed using the dot operator (`.`). 38. **What are the differences between structures and arrays?** - **Structures**: Store dissimilar values. One structure variable can be assigned to another. - **Arrays**: Store similar values. One array variable cannot be assigned to another. 39. **What is the size of a structure?** - The size of a structure is the sum of the sizes of all its members. 40. **What is a union?** - A union is a user-defined data type that can store a value of different data types, but only one at a time. This allows for efficient memory usage. 41. **What are the types of files we can create using C?** - C supports creating both `text` and `binary` files. 42. **What are the file-handling functions present in C?** - Common C file-handling functions include: - `fopen` - `fclose` - `fgetc` - `fputc` - `fgets` - `fputs` - `fprintf` - `fscanf` - `fread` - `fwrite` - `fseek` 43. **What are the file opening modes present in C?** - File opening modes specify the purpose you want for a file: - `r`: Open for reading - `w`: Open for writing (create if doesn't exist, truncate otherwise) - `a`: Open for appending (create if doesn't exist) - `r+`: Open for reading and writing - `w+`: Open for reading and writing (create if doesn't exist, truncate otherwise) - `a+`: Open for reading and appending (create if doesn't exist) 44. **How to access structure members by their pointer?** - The arrow operator (`->`) is used to access structure members through a pointer. 45. **What is the difference between normal variable and array variable?** - A variable can store only one value at a time. - An array variable can store several values at a time. 46. **How to declare a variable?** - The syntax for declaring a variable is: `data_type variable_name-1, variable_name-2...variable_name-n;` This covers many of the fundamental concepts in the C programming language. Remember that practice and understanding code examples are key to mastering this potent language!

Use Quizgecko on...
Browser
Browser