2nd part chpter 4 contdinued

Upload: aunbhav-sarma

Post on 03-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 2nd Part Chpter 4 Contdinued

    1/4

    Q What is EBCDIC ?A EBCDIC means extended binary code for decimal interchange. Just like ASCII we

    have EBCDIC to represent characters in numerical format inside the computer

    Q How is the letter A represented inside computer in ASCII format?

    A In ASCII format letter A is represented with a vale of 65. B is 66 , C is 67 and so on

    Q Write a program to get ASCII value of A?Ans

    void main(){ clrscr();

    printf(Ascii value of A is %d, A);getch();

    }

    Q Write a program to get ASCII value of any character entered from the keyboard?

    Ans #include#includevoid main(){ char ch;

    printf("enter a character ");scanf("%c",&ch);printf("Ascii Value is %d",ch); // here we print the integer value of the charactergetch();}

    Q Write a program to get ASCII value of X?Ans Try yourself

    Q What is escape sequence?A. Character combinations consisting of a backslash (\) followed by a letter or by acombination of digits are called "escape sequences." To represent a newline character,single quotation mark, or certain other characters in a character constant, you must useescape sequences. An escape sequence is regarded as a single character and is thereforevalid as a character constant. Escape sequences are typically used to specify actions suchas enter key for new line(\n) and tab movements (tab key i.e \t) .

    Example printf(\n\n hello);

    Before hello is displayed the scape sequence \n is given twice so it will leave two blanklines then it will display hello on the monitor.

    A table list of commonly used escape sequence is given in page 150.

    Q What is variable?

  • 7/27/2019 2nd Part Chpter 4 Contdinued

    2/4

    A. Variables are identifiers used in the program which hold information inside itExample

    void main(){

    int a;

    char b;a=2;b=x;

    }In this program

    a identifies itself as an integer variable , so it will occupy 2 bytes in memory and it isholding the informational value 2 similarly b is a character variable it occupy 1 byteand information inside it is x.So Variables are like containers which hold information and occupy some space inmemory.

    Q What is the difference between constant and variable?A Variable is identifier, but the value inside a variable can change.Constants are fixed , say 12 it is a numeric constant , if in India it is 12 in America also

    it is 12 .

    examplevoid main(){

    int a;const int b = 5;a=2;printf( value of a is = %d ,a);a=3;printf( value of a is = %d ,a);a++;printf( value of a is = %d ,a);

    }In this program a is integer, first a is assigned value 2, then it is assigned value 3 , then ais incremented by 1 , so its value now is 4. so we see that as value can change from timeto time. But b is declared as integer constant with value 5 , if we happen to write b=6 orb= any other value the C compiler will not allow this. It will give error cannot changeconstant value

    So constants cannot change variable can cange.

    Q. what is special character?

    A Symbols like #,$,%,*, {,}, [,], , etc are special characters.

  • 7/27/2019 2nd Part Chpter 4 Contdinued

    3/4

    Q what is junk value or garbage value?

    A Junk values or garbage values are unwanted values in the program. If we declare avariable In our program and we dint assign any value to it, then c compiler will give anyvalue to the variable which is a junk or garbage value.

    Q what is an expression>?A. An expression consists of variables, constants and operators combined to performsome useful computation.

    Example

    void main ()

    {

    int x , y;

    y=2x+3

    } Here in his example y=2x+3 is an expression to calculate or compute the valueand after value is calculated it is assigned to y. here we see that x, y are variables, 2,3are constants and (+,=) are operators .

    Q What is the difference between = and = =?

    A. = is an assignment operator. = = is comparison operator.

    Example

    void main ()

    {

    int x, y;x=5;

    y=x

    } Here we se we are writing x=5 that means x will be assigned value 5, then wewrite y=x , it means what ever value is inside x that will go to ya also , so y will also begetting value 5 . so = is used when we want to put some values or assign some value to avariable.

    = = is used for comparison i.e comparing two values

    Example

    void main ()

    {

    int x, y;

    if (x = = y)

    }here using = = we are checking that whether the value of x and y are same or not

  • 7/27/2019 2nd Part Chpter 4 Contdinued

    4/4

    Solved Ques / Ans for chapter 4

    Fill the blanks

    Ans 1. Auto

    Ans 2. Value

    Ans3. integers

    Ans 4. Float

    Ans 5 letter or underscore

    Ans 6 Reserved word

    Ans 7 Macro

    True of false1. false ( because printf is not a macro it a function)

    2. True( Because internally inside computer it is interpreted as integer)

    3. True( Because every character is enclosed propely inside )

    4. False (because we can have octal and hexadecimal constants in c)

    5. False (Negative value is not allowed in unsigned integer. Unsigned means therecannot be any negative sigh, only positive integer is allowed).