Skip to main content

Posts

Showing posts from May, 2020

call by value and call by reference in C also difference between them - Computer science fundamental tutorial

Pointer A pointer is a variable like name with points which represents storage location in memory(RAM). Address operator(&) : - the symbol ‘&’ is an address operator which is used to access address of a variable and assign it to it to a pointer to initialize it. Indirection operator(*) : - the symbol’*’ is an indirection operator which is access the value of variable through a pointer. Pointer as function argument: - A pointer as an argument in function declaration when a function with a pointer argument is called the calling program pass the address (not the value) of a variable to the argument. In C language a function can be called by the calling programming in two ways. There are described briefly below     1. Call by value: - when a function is called by the calling program , the values to the argument in the function are supplied by the calling program. The value supplied   can be used inside the function. Any alteration to the val...

Dynamic memory allocation in C - Computer science fundamentals tutorial

Dynamic memory allocation Dynamic memory allocation refers to the method of allocating a block of memory and releasing it when the memory is not required at the time of running the program. A block of memory can be used to store values of simple or sub scripted variable and a block of memory can be accessed using a pointer. Malloc(), calloc(), realloc() are the function used in dynamic memory allocation and this function are available in the header file <alloc.h>. when we have to dynamically allocate memory for variables in our programs then pointers are the only way to go. When we use malloc() for dynamic memory allocation then you need to manage the memory allocated for variables yourself. malloc() :-   malloc() is used to allocate a single memory block memory to store value of specific data type. Syntax of malloc() : -   pointer variable name=(type *)malloc(size); Example: - ptr=(int*)malloc(100); ptr= (int*) malloc(size of (int)); calloc(...

storage classes in C - Computer science fundamentals tutorial

Storage class in C Storage class defines the scope (visibility) and lifetime of variables and/or functions declared within a C program.   It stored in RAM or CPU register. There are Four storage class into which variables are declared & stored. 1.    Auto storage class. 2.    Static storage class. 3.    Extern storage class. 4.    Register storage class. 1.    Auto storage class : - Variable declared in this class is stored In RAM. This is the default storage class and the keyword ‘auto’ is used declare variables. Auto variables are active in a block in which they are declare. Auto storage class is commonly used in all C program without a keyword ‘auto’. Example:- auto int a; 2.    Static storage class :- Variables declares in this class are also stored in the RAM. The keyword ‘static’ is used to declare these variables. Similar to auto variable, the static variable are also active in the block ...

function in C - Computer science fundamentals tutorial

Functions in C Functions are subprogram which are used to compute a value or perform a task. They can't be run independently and are always called by main() program or by some other function. Types of function  : -  1.  Library or built in function : - Library function are used to perform  standard operation. Example printf(), scanf(), etc. 2.  User defined Function : - User defined function are self contain block of statement which are written by user to compare a value or to perform a task. They can be called by the main program repeatedly as per requirements. Uses of function : -  1. Functions are very much useful when a block of sentences has to be executed again and again. 2. When the program is to long or complex function are called to perform each task sequence from  main program.   3. Functions are also used to reduced the different during debugging a program Function declaration :-  ty...

type casting in C. - computer science fundamentals tutorial

Typecasting in C Typecasting is also known as "forced conversion". It refers to changing variable one data type to another data type.          Typecasting in can be certified into following two types: - 1) Implicit type casting. 2) Explicit type casting. Implicit type casting : - It is also known as "Automatic type conversion". It is done by compiler on its own without any external trigger from user. Generally takes place when in an expression more than one data type is present in such condition. Type conversion take places to avoid data lose. Example : - #include<stdio.h> main() {   char y = 'a';   int b = y; printf("%c",y); printf("%d",b); } Explicit Type casting : - This process also called 'Type casting' and it is user defined . Here the user can type cast the result to make it of particular data type. Example : - #include<stdio.h> main() { int m...

strupr string function in C - Computer science fundamentals tutorial

strupr() function in C In string strupr() function is used to converts lower case string into upper case. syntax:-  char*strupr(char*str). Example : - example of this function is given below Program code   #include<stdio.h> #include<string.h> int main() {     char str[ ] = "computer";     printf("%s\n",strupr(str));     return  0; } output

Loops in C programming - Computer science fundamentals tutorial

Loop control structure **note** PDF version of this post also available. To get the PDF click the link given at the end of this post. Loop control structure consist of two parts. the two parts are a body  of loop and control statement.  Loop control structure are used to execute and repeat a block of statement depending on value of a condition There are three types of loop control statement- 1. For loop. 2. While loop. 3. Do - while loop. 1. for loop : - The For loop provides a mechanism to repeat a task until a particular condition is true. For loop is usually known as determinate or definite loop because the programmer knows exactly how many times the loop will repeat. The number of times the loop has to be executed can be determined mathematically by checking the logic of the loop. Syntax of for loop : - For(initialcondition;<endcondition>;increment/decrement) {    Statement block; } Example of For loop : - Explanat...

Decision Control Statements in C - FCST

  Decision Control Statement **NOTE** PDF version of this post also available. to get the PDF of Decision Control Statements in C click the link given at end of this post. All statements written in a program are executed from top to bottom one by one. Control statements are used to execute/transfer the control from one part of the program to the another depending on condition. These statements are also called conditional statement. There are two types of decision control statements- 1) If-else statement. 2)Switch statement. If-else statements has three types. They are  i) normal if-else statement. ii)else-if statement. iii) nested if-else statement. If-else statement The if   statement plays a vital role in conditional branching. Its usage is very simple, the test expression is evaluated, if the result is true, the statement(s) followed by the expression is executed else   if the expression is false, the statement is skipped by the comp...