You are on page 1of 13
Q. What is computer program and computer programming? Computer Progr: Computer is a device that follows the instructions given to A set of instructions for the computer to perform a task is called computer program. Computer program is also known as software. A computer program is written in a programming language. A person who knows how to write computer program correctly is called programme! Computer Programming ‘The process of writing the instructions for the computer is known as computer programming, The instructions are given to the computer for execution. The problem is solved when the computer executes these instructions. Q. What is programming language? What do you know about C language? Programming Language A special language used to write computer programs is called programming language A programming language defines the rules for writing computer programs, A large number of programming languages are available for writing computer programs. Some most commonly used programming languages are as follows: © Java 1 ° CH ° CH * Python C Language Cis a popular general-purpose programming language. It was developed by Dennis Ritchie at Bell Labs between 1969 and 1973. It provides the facilities to write application software as well as system software. Q. What is a programming environment? Describe integrated development environment (DE). Programming Environment Programming environment is a collection of all the necessary tools for programming, It works as a basic platform to write and execute computer programs. It is important to setup the programming environment before writing the programs. Integrated Development Environment (IDE) A software that provides a programming environment for programmers to write and execute computer programs is known as Integrated Development Environment (IDE). An IDE provides a graphical user interface (GUD, It means that the user can interact with the IDE. using windows and buttons to provide input and get output. An IDE consists of different tools to help the programmer in writing, executing and testing computer programs, These tools include text editors, compilers and debuggers ete. Examples Some examples of IDEs for C programming are as follows: 1, Visual Studio 2. Xeode 3. Coder:Blocks 4. DevO+ Wi soctee- Sees ox" S6agle ri xmalaaiorson aieaeeee sue oo iée fs [Clea meee oooleascy — Eye Code::Blocks iiss ein a feces x i A cosetocs x] hierdie XAG x] Qoaby x] Padme > pacer uns tes ron es se) ede ech e 5 ot igure: Main interface of Code::Block Q. Explain the modules of text editor and compiler for the C programming environment. ‘Text Editor A text editor is a software that allows the programmers to write and edit computer programs. All IDEs provide their own specific text editors where the programmers can write the programs. The program should be saved before it can be executed. The C program can be saved with an extension of .e such as maine ‘The following figure shows the text editor of Code::Blocks IDE. It contains C program saved as maine TGAOriKaaiagiorseon Blrwceecene ex Wino sa Figure Text eitor in Code::Blocks Compiler Computers only understand and work in machine language that consists of Os and Is. ‘The programs written. in high-level languages must be translated into machine language to be executed. A compiler is a program that converts the instructions of a high-level language into machine language. The compiler also detects syntax errors. It does not compile a program that contains a syntax error. ‘Computer Program Files Compilation ‘Computer Binary File Figure: Program Execution Q. Deseribe the importance of syntax in programming. What is the cause of syntax errors in programs? Syntax A set of rules for writing computer programs in a programming language is known as syntax. All program statements must be written according to the syntax, The syntax works as the grammar of a programming language. There are many programming languages. Each language has its own syntax. The program written in a specific programming language must follow its own syntax, Syntax Errors It is important to write a computer program according to the syntay of the programming language. Syntax errors occur when rules of programming languages are not followed in writing the computer program. The compiler detects syntax errors. The compiler generates an error message to describe the cause of the error. A program cannot be compiled if it contains any syntax error. Q. Write the procedure to write, save, compile and execute a C program in CodeBlocks. 1. Writing a C Program ‘The following procedure is used to write a C program in CodeBlocks: 1. Start Code Blocks IDE 2. Click File > New > Empty File, A new empty fie will appear in the IDE. a Fle felt view Search Project ul Debug Fertan wnSmith Tools Toole Pligine Donte Stings Help BBAGcrsXmalQaiorsen ed ~Codelocs 1 o Ponte Windows (CRLF) deat ‘Une 1 Col), Pos Inset Modied Renite 3. Write the following code: ‘rinelude void main t printf("Hello world! 3 2. Saving a C Program ‘The following procedure is used to save a C program in CodeBlocks: 1. Click File > Save File or press Ctr FS, The Save file dialog box will appear. Sete SS GOrr> ax > [4] | Seorch C5202 P)| Orgonize + New folder e 3k Favorites FE) Morn FE oeitop Te Demonte ‘BL RecentPhcee Tye Nokemsmatch your seach i Liees 1B Documents od Music Ba Pictures BF viscor gc a , [ pe ee © Hide Fetes | se) [cee 2. Type main.e in File name box and click Save. The program will be saved. 3. Compiling a C Program ‘The following procedure is used to compile a C program in CodeBlocks: 1. Click Build > Compile current file or press Ctr}+Shift+F9, The program will be compiled and the result will appear in Logs & Others pane. 4. Executing C Program The following procedure is used to execute a C program in CodeBlocks 1, Click Build > Run or press CtrF¥F10, The program will be executed and the result will appear in the console screen. Q. What are reserved words? Write a list of reserved words in C language. Reserved Words Reserved word has a predefined meaning and purpose in a programming language. ‘The meaning and purpose of a reserved word is defined by the developer of the language. It cannot be changed or redefined by the programmer. It can be used for the same purpose for which it is defined. The reserved words are also known as keywords. Each programming language has a list of reserved words. C language provides 32 reserved words. The reserved words in C language are written in lowercase. List of Keywords ‘The complete list of reserved words in C language is as follows: Auto double int struct Break else long switch Case enum register typedef Char’ extern return union Ce float short unsigned Continue for signed void Default goto sizeof volatile Do if static while igure: Reserved words in language in programs. Give some examples. Header Files Header files are collection of standard library functions to perform different tasks. ‘There are many header files for different purposes. Each header file contains different types of predefined functions, Many header files can be included in one program. The header file must be included in the program before calling any of its functions in the program The extension of a header file is -h. The include statement is used at the top of the program to inelude header files. The name of header file is written in angle brackets <> Syntax ‘The syntax of using header files is as follows: #inelude ‘The name of header file can also be used in double quotes as follows’ Hinclude "header_file_name" Examples ‘Two examples of header files are as follows: Hinclude void main() t printf("Hello World of C Programming."); printf("Programming makes life interesting."); Q. Write some important points for writing a C program, Some important points to write C program correctly are as follows: 1. The sequence of statements in C program must be the same according to which they need to be executed. 2. C language is case-sensitive. It means that it differentiate between lowercase and uppercase letters. For example, main and Main are different words in C 3. Each statement in C progranr must end with a semicolon (;). The compiler generates syntax error if'any statement is not terminated by a semicolon, Q. What are comments in C program? Describe their purpose and syntax. ‘Comments ‘Comments are the statements in the program that are not executed, The comments are usually written to describe the code in natural language such as English. The comments can be added anywhere in the program Purpose of Comments Comments can be considered as documentation of the program. The mai using comments in the programs is as follows: purpose of 1. Comments allow other programmers to understand the code easily. 2. Comments are notes about the code that explain its purpose. It helps in understanding the program even after a long time. Syntax of Comments ‘Comments can be added to the programs in two ways: 1. Single-line Comments ‘The single-line comments start with //. Anything after // on the same line is considered as comments. An example of single-tine comments is as follows: 1/ The body of the main function 2, Multi-line Comments ‘The multi-line comments start with /* and end at */, Anything between /* and */ is considered as comments. The /* and */ can also be used to enter comments on a single Tine. An example of adding comments on many lines is as follows Example The following example uses different types of comments in a C program: ‘include /* This program is written in C language. It simply displays a message on the screen using the built-in function printf */ void main() { 1/ The body of the main function printf{"Hello World of C Programming."): 1/ The end of the program 3 Q. What is character set? List different types of characters in C language. Character Set Character set is a set of letters; digits and special characters used to construct words and statements in a language. Every programming language has a set of characters, These characters are combined to form variables, constants, reserved words and write instructions. C language has its own character set that contains alphabets, digits and special characters. 1. Alphabets C language supports all the alphabets of the © Lower case letters: a to z © Upper ease letters: A to Z 2. Digits C language supports 10 digits from 0 to 9. The digits are used to construct numerical values. 3. Special Characters CC language supports many special characters. Some special characters in C language are as follows ~@HS%°RA() -+ Q. What is constant? Explain different types of constants in C language. ‘Constant A constant is a quantity that cannot be changed during program execution. The constant are used in the programs to specify the values that remain the same throughout the program execution. For example, the value of Pi is 3.141 and can be used as a constant in a program. ‘Types of constants C language provides the following types of constants 1. Integer Constant Integer constants are numeric values without a fraction or decimal point, Both positive and negative integer constants are used in C programs. The minus sign - is used for negative integer constants. If no sign is used, the value is positive by default. Examples Some examples of integer constants are as follows’ 87 45 -10 $s 2. Real Constants Real constants are numeric values with a fraction or decimal point, Both posi negative real constants are used in C programs. The minus sign - is used for negative real ve by default. Real constants are also called e and constants, If no sign is used, the value is posit floating-point constants. Examples Some examples of real constants are as follows: 30.75 10.22 “13.42 75.0 3. Character Constants Any character written within single quotes isknown as character constant. A character constant can be an alphabetic, a digit or a special symbol. Examples Some examples of character constants are as follows: ie yh gE as Q. What is a variable? Expl Variable A variable is a named memory location. Its used to store a value such as input data or the result ofa calculation. The value ofa variable may change during the execution of program, However, the name of variable cannot be changed. If a new value is stored in a variable, it replaces the previous value. Each variable has a unique name called identifier, A variable also has a data type that indicates the type of data that can be stored in the variable, Q. Write down the rules for naming variables in C language with examples. Each variable must have a unique name or identifier. The variable name must be meaningful and readable. It helps the user to understand the purpose of the variable. For example, a variable to store the marks of student should be marks. Different rules for naming variables in C Language are as follows: 1. Variable may include letters, numbers and underscore (_). 2. The first character of variable must be a letter or underscore_. It cannot begin with a digit. The variables minute, #home and 2kg are invalid. 3. Blank spaces are not allowed in variable names. For example, my ¥: and your car are invalid 4. The special symbols such as @, $, % are not allowed in variable names. For example, Scost and tot.al are invalid variable names, 5. Reserved word cannot be used as variable name. For example, are invalid variables, 6. A variable can be up to 31 characters long for many compilers. Ifa variable consists of more than 31 characters only first 31 characters will be used. The remaining characters will be ignored. nt, void and while Examples Some examples of valid variables are as follows: Marks subl test £ name Q. Differentiate between variable and constant. ‘The difference between variable and constant is as follows: Variable Constant 1. The value of variable can change during |1. The value of constant cannot change program execution. during program execution 2. Iirefers toa memory location. 2 Tirefers toa value 3. An example of a variable is n. 3. An example of a constant is 3.141. Q. What do you mean by data type of a variable? List different data types in C language, Data Types of a Variable ‘The data type specifies the type of data that can be stored ina variable. Every data type has arrange of values and requires different amount of memory. The compiler allocates memory space for each variable according to its data type. It is important to specify correct data types for the variables in a program so that data can be stored correctly C language provides the following data types: ‘Types of Data Data type in C Examples Integer int 5, 23, -9 Real float Character char ‘Table: Data types 1. Integer Data A variable of integer data type can store integer value. An integer is a numeric value with no decimal point or fraction such as 10, 520 and -20, The int keyword is used to declare a variable of integer data type. The int data type takes 4 bytes of memory, It can be signed or unsigned. signed ‘The signed int can store both positive and negative values. Its value ranges from -2,147,483,648 to 2.147, 483.647. The type int is considered signed integer by default unsigned int ‘The unsigned int can only store positive values. Its value ranges from 0 to 4,294,967,295. The keyword unsigned int used to declare the unsigned integer. Some compilers use 2 bytes to store an int value. The range of int value in these compilers is from -32,768 to 32,767. 2. Floating Point Data A variable of floating-point data type can store real numbers. A real number is a numeric value with a decimal point or fraction such as 2.5, 4.0 and -5.91. The float keyword is used to declare a floating-point variable. The float data type takes 4 bytes of memory. Its value ranges from 3.4x10% to 3.4x10, The float variable provides a precision of 6 digits. ‘The precision refers to the number of digits after the decimal point in a floating value. 3. Character Data Type A variable of character data type can store one character. A single character may be an alphabet, a digit or a special character. The character value is normally given in single quotes such as a’, 's,'S', and #', The char keyword is used to declare a variable of character data type. Ittakes 1 byte in the memory. Q. What is a variable declaration? Explain with examples. Variable Declaration ‘The process of specifying the variable name and its type is called variable declaration. All variables must be declared before they are used in C program. A variable can be declared anywhere in the program before its use. Syntax ‘The syntax of declaring variables is as follows: data_type variabl name; data_type It indicates the type of data that can be stored in the variable variable_name —_ It refers to the memory location of the variable. Examples Different types of variables are declared as folows int marks; float average; char grade; In the above examples, int, float and char are keywords that indicate data types. The words marks, average and grade are variable names. Many variables of same data type can also be declared in single statement. Each variable name is separated by comma as follows’ int num1, num2, sum; Q. What is variable init ation? Explain with examples. Variable Initialization The process of assigning a value to a variable for the first time is known as variable initialization. A variable can be initialized both at the time of variable declaration or after declaration Syntax ‘The syntax of initializing a variable at the time of declaration is as follows: type_name variable = value; type_name It indicates the data type of the variable to-be initialized: variable It is the name of the variable to be initialized, = Itis the assignment operator used to initialize a variable, Value It is the value to initialize a variable. Example An example of variable initialization is as follows: Hinclude

You might also like