functions in C types - pre define & user define user define - 4 * function with * function with * function with * function

with syn returntype funname(argument/s) { statement/s; return val; - if return type given } Adv of functions - functions r used for implement the modular appoach. * Simplicity * Reusablility * Performence Improve * Error Handling & debugging easy. // Type 1 - No pass & no return #include<stdio.h> void disp() { printf("I m inside disp\n"); } void main() { clrscr(); disp(); getch(); } // Type 2 - No pass & return #include<stdio.h> int getVal() { int x; printf("Plz enter any Number : "); scanf("%d",&x); return x; } void main() { int a,b,c; clrscr(); a = getVal(); b = getVal(); c = a + b; printf("Sum is = %d",c); getch(); } // Type 3 - pass & no return #include<stdio.h> void sum(int x,int y) Types no pass argument & no return value. - no pass no return no pass argument & return value. - no pass & return pass argument & no return value. - pass & no return pass argument & return value. - pass & return

&b). clrscr(). } // Type 4 . prototype in C or Function declaration in C #include<stdio.h> void disp(). // prototype for disp . scanf("%d %d".4 Types + 2 Types extra Concrete methods Abstract methods * with body * without body.h> int sum(int x.abstract method void main() { clrscr(). for disp . getch().&a. abstract method .&a.&b).p("jaja").pass & return #include<stdio. getch(). disp(). printf("Plz enter 2 Numbers : "). printf("Sum is = %d\n". * can call without overriding* 1st override then we can call it void disp(){S.b). printf("Plz enter 2 Numbers : "). scanf("%d %d".c).b. getch().c. printf("Sum is = %d\n". clrscr().b. } void main() { int a. } void disp() // def.b).{ int c = x + y.o.c).} void disp(). } methods in java = C & C++ . c = sum(a. } or .int y) { return = x + y.override { printf("I m inside disp\n"). sum(a. } void main() { int a.just prototype for method or like function declarations in C & C++ or like pure virtual functions in C++.

} abstract void sub(int a.int b).Concrete method { printf("I m inside disp\n"). bcos using classes java support only single inheritance.all abstract methods of an abstract class must be override in child class else child class is also a kind of abstract class. // to create simple abstract class abstract class Calc { void sum(int a. then one class can extends only with one abstract class or one concrete class.it is a kind of pure abstract class. now inherit with concrete class & the place of abstract class used to concept of interfaces. we can't create instance of an abstract class it is only for inherit purpose. used for create/design the Generic methods.if one class has one or more abstract methods then that is called an Abstract class.we can can create an abstract class without any abstract method? Ans. just declare as abstract. * can create instance & inherit also.Abstract classes not in used. System. interface .out. used for create/design the Generic methods. but can't create the direct instance.h> void disp() // prototype + def. conditions . getch(). Q. } classes Type .2 Types Concrete class * only Concrete methods. can create. * can't create instance inherit only. memory for methods provided by the abstract class.#include<stdio.Abstract classes r used for memory management. } void main() { clrscr().yes. Abstract class . disp().int b) // concrete method { int c = a + b. future .println("Sum is = "+c). Abstract class * Concrete + abstract methods. Adv . // abstract method } // class inherit with abstract class class MyCalc extends Calc . .

} } .sum(100. o.int b) // method of Calc class { int c = a .b.20).out.sub(100. } public static void main(String aa[]) { MyCalc o = new MyCalc().println("Sub is = "+c).{ void sub(int a. System. o.20).

Sign up to vote on this title
UsefulNot useful