Posts

File management example

example 1: View this gist on GitHub example 2: View this gist on GitHub

pointer and array

pointer and array In a array the first element of array that we represent as arr[ 0 ] it's self a pointer. and it also represent as *arr by using this pointer array relation ship we can access the all the element of array by *( arr + 1), *(arr + 2 ) and so on...  

pointer to pointer

Image
pointer to pointer is nothing but one pointer is holding anther pointers memory location. declaration of pointer to pointer  data_type ** pptr;   initilization of pointer to pointer pptr = &ptr;   accessing value of pointer to pointer  **pptr; Example:  

pointers

pointers pointers is one of the data type that use to store memory location of the already declared data type, to store integers we have int data type, to store floating point values we have float data type, to store characters we have char datatypes, as like to store memory of something we have pointers data types. rule for the pointers are it can hold memory of same data type, means if we want to store int data types memory then we have to use int pointer and for char we have to use char pointer you got the point... Declaration of pointers:  data type * variable_name ; Example: int * ptr ; Initialization  of pointers: pointer = &variable name  // now pointer holds memory location of variable ptr = &a; Accessing the value at memory  by using * operator *ptr gives value stored in that location declaration and Initialization of pointer: // declare ptr and store memory of variable togatore data_type * ptr = & varia...

recursion vs iterative approach

recursion vs iterative approach Iterative     Recursive In iteration, a problem is converted into a train of steps that are finished one at a time, one after another Recursion is like piling all of those steps on top of each other and then quashing them all into the solution. With iteration, each step clearly leads onto the next In recursion, each step replicates itself at a smaller scale, so that all of them combined together eventually solve the problem Any iterative problem is solved recursively Not all recursive problem can solved by iteration does not use Stack It uses Stack

Example of recursive functions

1 Finding Factorial View this gist on GitHub 2 Fibonacci series number View this gist on GitHub

Two-dimensions array

Two-dimensions array Two-dimension arrays are nothing but the arrays as elements of one array.rather then storing the data if we store the arrays in elements then it becomes 2D array. 2D arrays are also similar to the matrix. Declaration of 2D array: Declaration of  2D arrays is quite similar to declaring the one-dimension array, here we also need to specify the size of the second array. syntax: data_type name_of_array [ size_of_raw ][ size_of_colomn ]; example: int  arr[ 2 ] [ 2 ]; it declare 2 X 2, 2-D array. int arr [ 3 ][ 2 ]; its declare 3 X 2, 2-D array. Declaration of 2D array with initializing elements: 1 int arr[ 3 ][ 4 ] = {  {0 ,1, 2, 3}, { 4, 5, 6, 7}, { 8, 9, 10, 11} }; This method first declares the 3 X 4 array then assign value to them according to the position.in this case arr[ 0 ][ 0 ] to arr [ 0 ][ 3 ] is assigned as 0,1,2,3 then arr[ 1 ][ 0 ] to arr [ 1 ][ 3 ] is assigned as 4, 5, 6, 7  and arr[ 1 ][ 0 ] to arr [ 1 ][ 3 ] is assigned as 8, 9,...

Arrays

An Array is group similar data of one particular data types, the array's elements are continuous in nature when the array is declared the location of the array elements is continuous in memory. advantage of the array is we can assess the similar type of data by using only one variable and as the elements of an array are continuous in memory we can assess the element just by knowing the address of the first element we will see that in pointers. We access the elements of the array by the index in c programming the index of the array starts from 0 to N-1,  where  N is the length of the array. For example, if we want to access the first element of the array then we can use array[ 0 ],  and array[ 4 ] gives us the fifth element of the array. here the 0 and the 4 is the index for the first and the fifth element of the array. Declaration of array: Declaration of the array is the same as declaring a variable of any other data type, but in the case of an array we need to men...

strings

A string is nothing but an array of characters, the difference between the string and the array of character is the string is terminated by the null character "\0". we don't need to add the null character at the end of the strings compiler do that for us when the code is compiling. In string, each character is going to take one byte and one extra byte is required to store the null character. so the size of the string is always going to the length of string + 1 bytes. Declaration of string: Declaration of sting is the same as the declaration of an array. but this time the data type is going to char because we are going to store characters inside the string. char  array_mane[size]; we need to include the null character in the size. example: char name[12]; char array[ 5 ]; Declaration of string with initializing elements: 1 char name[15] = { 'M' , 'y' , 'c', 'o', 'l', 'l', 'e', 'g', 'e', 'b...

calling a function

calling a function calling a function is a method to invoking the function. we can invoke function by two method call by value call by reference call by value In this method we pass the value or parameter while we calling the function and the parameter's value is copied to the actual function's parameters in your example the value of x and y are copied to local variable x and y of function Call by reference  in this method we pass the memory location of variable as parameter when we calling the function. in your example the memory location of x and y is stored into the a and b then we assessing the values at a and b by using * operator to check maximum out of them. Example: View this gist on GitHub

parameters, parameter passing in function

parameters, parameter passing in function In function parameters are those that we pass in function. parameters are decided when the function is created, the parameters passing

String Functions

String Functions Function Use strlen Finds length of a string strlwr Converts a string to lowercase strupr Converts a string to uppercase strcat Appends one string at the end of another strncat Appends first n characters of a string at the end of another strcpy Copies a string into another strncpy Copies first n characters of one string into another strcmp Compares two strings strncmp Compares first n characters of two strings strcmpi Compares two strings without regard to case ("i" denotes that this function ignores case) stricmp Compares two strings without regard to case (identical to strcmpi) strnicmp C...

Precedence And Associativity In C

Operators precedence: It defines the order of evaluation of operators in an expression. Associativity defines the order in which operators of the same precedence are evaluated in an expression. Associativity can be either left to right or right to left. Operator precedent example: 10 + 20 * 30 Now here addition operator has lower precedence and multiplication operator has higher precedence, there for the multiplication operator evaluate first and our equation became 10 + 60 is equal to 70 Here 10+20*30 is calculated as 10+(20*30) is equal to 70 Operator Associativity: Example: '*' and '/' have the same precedence and their associativity is left to right. 100/10*10 is evaluated as (100/10)*10 here / and * have the same precedence but left to right associativity so division operator evaluate first because it comes first from the left side and then the multiplication operator is evaluated 100/10  *10 10* 10 100 Example: 100 + 100/10 - 2 *10 will be evaluated as follows Ste...

Functions In C

    function initialization / definition: here we define your functions with its entire logic. If we defied the prototype of the function then the function definition always defined after defining the prototype of the function. syntax: returntype_of_function  function_name( arguments...){ //entire logic; // return value; } example: int sum( int a, int b){ int x; x=a+b; return x; } Here, In your example, we first define your function definition as int sum( int a, int b) here we write return type as int because at the end the function is going to return an integer value  ( x ). Then we write name of the function as a sum and in parentheses, we specified arguments as int a and int b . That means your function is going to tack two arguments of integer type when we are calling the function. More example on functions: Recursion: recursion means function calling it self. when function call it self in function definition it called as resursion. example of recursive function: fac...

prototype of function

prototype of function: prototype of the function is just the basic format of function, in the prototype we just decide datatype of function according to the return type of function and which type data type's and how many arguments is going to take when we want to execute the function. Simply, the prototype is a blueprint of your function. we put all prototype at top of code before the declaration of all functions including the main function because when the code is compiled the prototype is gives promise to the compiler that the function is declared anywhere in the program. Don't worry if you don't get it, its became more clear with an example. syntax: ReturnType Function_Name(argument1, argument2, argument3 , ...) Examples: int max(int a,int b,int c); void mul( float x, float y ); View this gist on GitHub

Introduction to Function in C

Functions In C programming language, the user just needs to call the function whenever the user wants to use the function. The example of system-defined functions are printf( ),scanf( ),getsThe functions are known as giving some output for one particular input or argument, we already work with functions like main( ), printf( ),scanf( ) in your  c programs. functions in C are use full in case of reducing code, to improve readability and reuse of code. If we want to perform a certain task frequently with different-different values or parameters then the use of function is convenient for us. It helps to reduce, reuse and improve the readability of your program. there are two types of functions system-defined functions user-defined functions system-defined functions: system-defined functions are already defined by the ( ),puts( ),pow( )... that are already defined by the system we just need to include the file/library that contains the function declaration for...

recursion examples

example: Factorial of number:

Recursion

Recursion: recursion means function calling it self. when function call it self in function definition it called as recursion. example of recursive function: factorial of number Fibonacci series marge and quick sort And many more... lets understand recursion with example: To understand recursion well lets understand first about stack stack: stack is used to store value and for that stack follows certain rules as LIFO or FILO mean whatever last value is stored it give that value fist ( last in first out) and value that stored first it given at last( first in first out ) both are same in logic way. Don't worry if you face any problem to understand stack it become more clear when we refer examples.  

Header Files

Header Files Header Files are already written files that simplify your work for example for i/o we have stdio.h header file by using that we can simply input and output stuff to the console. header files have .h extension with it and it is one of the example of modularity of c language, there are many header files are available in c language. stdio.h   defines core input output functions string.h  defines string handling function math.h  defines common mathematical functions and many more... To use these header files, first  we include them in your program and then we can start using their features syntax: #include <headder_filename.h> OR #include "header_filename.h"

indeterminate forms

  types of indeterminate forms:    [latex]\frac00[/latex]    [latex] \frac\infty\infty [/latex]    [latex] 0\;\times\infty [/latex]    [latex] \infty-\infty [/latex]    [latex] 1^\infty [/latex]    [latex] 0^0[/latex]    [latex] \infty^\infty [/latex] This all types of limits can be evaluated by using the L' Hospital's rule.   L' Hospital's rule If f(x) and g(x) are two function of x which can be expanded by Taylor's series in the neighborhood of x = a and if  [latex] \lim_{x\rightarrow a}f\left(x\right)=f\left(a\right)=0 [/latex],  [latex] \lim_{x\rightarrow a}g\left(x\right)=g\left(a\right)=0 [/latex], then [latex]\lim_{x\rightarrow a}\frac{f\left(x\right)}{g\left(x\right)}=\lim_{x\rightarrow a}\frac{f'\left(x\right)}{g'\left(x\right)}[/latex]   formulas: [latex]\lim_{x\rightarrow 0}\frac{\sin x}x=1[/latex]