Wednesday, 1 May 2019

ch-1

1. introduction
2. program introduction,show header file 
3.integer
4. variable declaration rule
5. data type and format specifier
6. float
7. character 
8. self practice test
9. string
10.  type conversion
11. value printing:-  decimal input value, negative , positive,  address,octal,hexadecimal.
12. procedural oriented means.
13 show object and source file
14 c program sequential step for execution
15 escape sequence \n, \t ,\b ,\r ,\a, \f ,\' ,\\, \"
16 unformated data type 
17 null
18 bit operator: shift operator,OR,AND compliment,XOR
19 increment/decrement operator
20 operetor precedence
21create header file

Length of  c identifier
some compiler take 247 length of identifier

Macros
\ is use for next line continuation

#include<stdio.h>
#define A {\
printf("hii"); \
printf("\nhru"); }
main()
{
A;
}

create header file
#include<stdio.h>
#define A{\

printf("hello");   }

save as ab.h
then:-

#include<stdio.h>
#include "ab.h"
main()
{
 A  ;
}
double data type
#include<stdio.h>
main()
{
double a=5.00000001;
printf("%.9lf",a);

}

float data type
#include<stdio.h>
main()
{
float a=5.00000001;
printf("%.9f",a);

}

main()
{
char name[30];
printf("enter name");
scanf("%[^\n]",name);
printf("name is %s",name);

  }

unformated I/O


Print String with space

1)

#include<stdio.h>

main()l

{

char a[20];

 printf("enter your name");

 scanf("%[^\n]",a);

 printf("you enter %s",a);

}

2)

Getch()

#include<stdio.h>

#include<conio.h>

main()

{
char a;
 printf("enter your character");
 getch();
 printf("you enter %c",a);
}
3)
Getche()
#include<stdio.h>
#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getche();
 printf("you enter %c",a);
}
4)
Getchar()
#include<stdio.h>
#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getchar();
 printf("\nyou enter %c",a);
}
4)
Gets()
#include<stdio.h>
#include<conio.h>
main()
{
char a[20];
 printf("enter your character\n");
 gets(a);
 printf("\nyou enter %s",a);
}
5)
Gets()  and puts()
#include<stdio.h>
#include<conio.h>
main()
{
char a[20];
 printf("enter your character\n");
 gets(a);
puts(a);
}
6)
Getch() putch()
#include<stdio.h>
#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getch();
putch(a);
}
7)
Getchar() putchar()
#include<stdio.h>
#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getchar();
putchar(a);
}
8)
Putc()
#include<stdio.h>
#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getchar();
putc(a,stdout);
}
9)
Putc() putch() putchar()
#include<stdio.h>
#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getchar();
//putc(a,stdout);   same as putch and putchar
//putch(a);
putchar(a) ;
}
10)
#include<stdio.h>
//#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getchar();
//putc(a,stdout);   same as putch and putchar
//putch(a); //come with conio.h and not supported by linux
putchar(a) ;   //comes with stdio.h and no problem with linux
}
#include<stdio.h>
//#include<conio.h>
main()
{
char a;
 printf("enter your character\n");
 a=getchar();
//putc(a,stdout);   same as putch and putchar
//putch(a); //come with conio.h and not supported by linux
putchar(a) ;   //comes with stdio.h and no problem with linux
}


MCQ: Which programming method is followed in C language
a) Algorithm
b) Flow-Charts
c) Procedural
d) Object Oriented


c) Procedural

1.2 Which of the following is true for variable names in C 
a) They can contain alphanumeric characters as well special characters. 
b) It is not an error to declare a variable to be one of the keyboards (like goto, static) 
c) Variable names cannot start with a digit 
d) Variable can be of any length 

Which of the following cannot be used as identifiers? 
A) spaces 
B) digits 
C) underscores
 D) letters 

ans c) Variable names cannot start with a digit 

Identify the correct sequence of steps to run a program 
A) Link, Load, Code, Compile & Execute
B) Code, Compile, Link, Execute & Load 
C) Code, Compile, Link, Load & Execute 
D) Compile, Code, Link, Load & Execute 

Find the output generated by the given
program.
#include <stdio.h.
void main()
{
 printf("Bre\nak");
}
A) Break
B) Bre\nak
C) Break

D) None 


1.3 Find the output of following code :
 int main()
{
int i=-2;
printf (“-i=%d”,-i);
return b;
}
a) –i=2 
b) i=-2
c) –i=-2 
d) –i=2

1.5 Which of the following is an incorrect assignment statement ?
a) N=m=0 
b) Value+=10

c) mySize=x<y?9:11
d) Value=+=10
d) Value=+=10

1.4 Which numbering system is not handled directly by the printf() conversion specifies ?
a) Decimal 
b) Binary
c) Octal 
d) Hexadecimal

Which one is incorrect statement for C Language?
A) C compiler supports octal integer constant.
B) C compiler supports hexadecimal integer constant.
C) C compiler supports binary integer constant.
D) C compiler supports decimal integer constant.


b) Binary

1.1 Which of the following is the correct order of evaluation for the below expression?
 a) */%+-=
 b) =*/%+- 
c) /*%-+= 
d) *%/-+=

ans a)
Which of the following software translates source code into object code? 
A) Compiler
 B) Interpreter 
C) Assembler 
D) None  


Which one of the following is not a keyword in C language?
A) main
B) endl
C) float
D) switch

ans B) endl

if you use main as a identifier , so it is not give an error because main is not predefine but predeclare , so as a good programming practice says , you  dont have to use main as identifier.

1.2 getchar() function is available in which header file?
a) Stdio.h
b) Conio.h
c) Math.h 
d) Header.h

a) Stdio.h

What will be the output of the following program?
int main()
{
int x=5;
 printf(“%d %d %d”,x,x<<2,x>>2);
}
a) 1 20 5
b) 5 1 20
c) 5 20 1
d) 20 1 5

ans  5 20 1

What will be output if you compile and execute the following „C‟ code?
void main()
{
 int i=4,x;
x=++i+++i+++i;
 printf(“%d”,x);
}
 A) 21
B) 18
C) 12
D) Compilation error

What will be the output of following program?
 #include main()
 {
 int x,y=10;
 x=y*null;
 printf(“\n %d \n”,x);
}
A) Error
B) 0
C) 10
D) Garbage Value



What will be the output of the following code?
 int main()
 {
 int x,y,z; x='1'-'0';   /* line-1 */
 y='a'-'b';         /* line-2 */
 z=x+y;
}

A) 0
B) Error because of incorrect line-1 only.
C) Error because of incorrect line-1 and line-2.
D) Error because of incorrect line-2 only.

Identify the invalid character constant:
A) '\n'
 B) '$'
C) '123'
D) 'p'


What is the binary number equivalent of the decimal number 12?
A) 1100
B) 1010
C) 1001
D) 1110

Precedence is used
A) To determine which operator evaluated first from left to right. 
B) To determine the level of an operator in a program. 
C) To determine how an expression involving more than one operator is evaluated. 
D) To check the expression is valid or not.  

True/False
1. #define is used to define symbolic constant.
2. const is a keyword that is used to define symbolic constant.  

3. A long double can be used if range of a double is not enough to accommodate a real number. TRUE
4. The modulus operator cannot be used with a long double. TRUE

5. 3+=3; evaluates to 6 

6. The default precision for printing of floating point values is 6. If the floating point number is more precise than 6 digits, it will be rounded.

7. A double data type number uses 64 bit giving a precision of 14 digits 

8. Every c program must have atleast one main() function section 

9. The precedence of arithmetic operators is (from highest to lowest) %,*,/,+,- 

10. Is the following statement valid in C? int my_num=100,000; 

11. We need to recompile the program before executing it even if there is no change in the source code.

Fill in the blank:

(A) Const      B) _//_     c) /   (D) Flowchart  _    e)  type conversion    f) d)  macro  (G) Six   (J)sizeof     k) flow chart    L) const M) scanf  N)math.h_


1. Pictoral representation of an algorithm is _______________ 
2  A variable can be made constant by declaring it with the qualifier ______ at the time of initialization 
3  The ________ Operator returns the number of byte the operand occupied. 
4  By default, the real numbers are printed with a precision of __________ decimal places.
5. A single line comment in C language source code can begin with _____
6. ________ operator is used to continue the definition of macro in the next line.
7. #define allow us to define ___________ 
8. ________ is a way to promote from lower to higher data type
9. ________ function reads data from stdin stream.
10. M_PI is a constant that represents 22/7 ratio. It is declared in _______ header file.

Questions

What are preprocessor directives? Why do we need them ? Explain various preprocessor directives

Write a C Program to swap two variables without using third variable

How can you create your own header file in C programming ?. Briefly Explain

Explain the role of linker and loader in compilation

Explain working of bit-wise exclusive OR and shift left operators in C with example.

Write a C program in which a scanf() function can read a complete paragraph of text

No comments:

Post a Comment

Index

ch-1 Introduction