404

Page not found.

Comments in C

2.9 What is Comment in C ?
2.10 Types of Comment : Single Line | Multi Line
2.11 Difference Between Single and Multi Line Comment

Types of Languages in C

File Handling in C

No Topic
17.1 Introduction to File Handling in C Programming
17.2 Type of Streams | FILE structure and FILE pointer
17.3 Types of Files : Text | Binary
17.4 Opening and Defining FILE
17.5 File Operations : Open a File | File Opening Modes
17.6 File Operations : Close a File | End of File (feof / EOF)
17.7 Character Input/Output : Getc | Fgetc
17.8 Character Input/Output : Putc | Fputc
17.9 Character Input/Output : Fgets | Fputs
17.10 Formatted Input/Output : Fprintf | fscanf
17.11 Direct Input/Output : Fwrite | Fread
17.12 Random Access : Ftell | Rewind | Fseek
17.13 Error Handling : Possible Ways
17.14 Database Operation : Add Record | Display Record
17.15 Database Operation : Modify Record | Append Record
17.16 Database Operation : Delete Logically | Physically
17.17 File Operation Functions : fflush | rename | remove

String in C

No Topic
12.1 Introduction to String Array
12.2 String Declaration
12.3 String Initialization
12.4 String Termination Character : NULL
12.5 Accepting String : scanf() | gets() | getchar()
12.6 Displaying String : printf() | puts() | putchar()
12.7 Arithmetic Operation on Characters
12.8 Converting String to Integer
12.9 String Library Functions : Strcat | Strcmp | Strcpy
12.10 String Library Functions : Strlen | Strstr
12.11 String Library Functions : sprintf() | sscanf()
12.12 Reading String with Space using scanf()
12.13 Difference between char *a and char a[] in C Programming

Storage Classes in C

Tutorial will explain different Storage Classes in C -

No Topic - Storage Classes in C
11.1 Introduction to Storage Class in C
11.2 What does Storage Class of Variable Determines ?
11.3 Storage Class Scope
11.4 Block Scope : Advantages | Disadvantage
11.5 File Scope : Advantages | Disadvantage
11.6 Storage Class : Auto | Extern | Static | Register

Pointer in C

This tutorial will provide you brief knowledge regarding pointer in C.

No Topic - Pointer in C
10.1 Pointer Basic : Basic Concept of Pointer
10.2 What is Pointer ?
10.3 Pointer Address Operator
10.4 Memory Organization of Pointer
10.5 Size of Pointer
10.6 Pointer Operator : Operator | Declaration
10.7 Pointer Operator : Initialization | De-Referencing
10.8 Void Pointer : Introduction | De-Referencing
10.9 Pointer Arithmetic Part 1 : Increment | Decrement
10.10 Pointer Arithmetic Part 2 : Addition | Subtraction
10.11 Pointer Arithmetic Part 3 : Differencing | Comparing
10.12 Illegal Arithmetic Operations on Pointer
10.13 Precedence : '*' and '&'
10.14 Meaning of (++*ptr) | Meaning of (*++ptr)
10.15 Double Pointer : Pointer to Pointer
10.16 Pointer to Constant
10.17 Pointer to Constant
10.18 Constant to Pointer vs Pointer to Constant?
10.19 Pointer to Array
10.20 Pointer to an Array of Function
10.21 Pointer to an Array of String
10.22 Pointer to Function
10.23 Pointer to an Structure | Union
10.24 Pointer to an Array of Structure | Array of Union
10.25 Application of Pointer in C
10.26 Common Mistakes while Using Pointer
10.27 Concept of Dangling Pointer

Function in C

This chapter will cover Function in C Programming -

No Topic - Function in C Programming
9.1 What is Function ?
9.2 What is main Function ?
9.3 Why Function is Used ?
9.4 How Function Works ?
9.5 Types of Function 1 : No Argument and No Return Type
9.6 Types of Function 2 : Argument and No Return Type
9.7 Types of Function 3 : Argument and Return Type
9.8 Rules for Writing Function ?
9.9 Function Parameter : Formal | Actual
9.10 Function Definition | Calling | Prototype Declaration
9.11 Calling Function : Types | Ways Part 1 | Part 2
9.12 Parameter Passing Sequence in Function
9.13 Introduction to Recursive Function
9.14 Pass by Value and Pass by Address

Loop Control Statements in C

Chapter covers Loop Control Statements in C Programming Language -

No Topic
7.1 For Loop : Introduction | Flowchart
7.2 Different Ways of Writing For Loop
7.3 Nesting of For Loop
7.4 While Loop Introduction
7.5 Infinite While Loop
7.6 Do-While Loop
7.7 Differenciation : For Loop Vs While Loop
7.8 Differenciation : For Loop Vs Do-While Loop
7.9 Differenciation : While Loop Vs Do-While Loop
7.10 Unconditional Jump : continue | break | exit

Decision Making in C

This chapter is dedicated to Decision Making in C -

No Topic
6.1 Conitional Statements - If Statement | If-Else
6.2 Nesting of Statements - Nested If-Else | Else-If Ladder
6.3 Multiple Condition inside If
6.4 Multiple Statements in If Block
6.4 Introduction to Switch Statement
6.5 Rules of Using Switch Case
6.6 Invalid Ways of Using Switch Case
6.7 Conditional Operation : ?: Operator | Rules
6.8 Jumping Statements : Goto Statement | Break

Data Types in C

This Chapter will cover all the Data Types in C Programming Languages.

No Topic
5.1 What is Data Type
5.2 Defining Type using Typedef
5.3 Integer : int | long
5.4 Character
5.5 Float : float | double
5.6 Enum

Overview of C

No Topic
2.1 Features of C Language
2.2 Application of C Programming
2.3 Compiler
2.4 Compiler Phases : Phase 1 | 2 | 3 | 4 | 5 | 6
2.5 Interpreter
2.6 Compiler Vs Interpreter
2.7 Execution of C Program
2.8 Type of Languages :
Low Level Language
Middle Level Language
High Level Language
2.9 What is Comment in C ?
2.10 Types of Comment : Single Line | Multi Line
2.11 Difference Between Single and Multi Line Comment

C Programming History

No Topic
1.1 History of C Programming
1.2 C Programming History Chart
1.3 Father of C Programming

C Programming History : Multiple Choice Questions

No MCQ Topic Questions
2.1 History of C Programming MCQ 10
2.2 About Dennis Ritchie MCQ 10

Question 4 : How to add two numbers using function pointer ?

How to add two numbers using function pointer ?

#include<stdio.h>
 int sum (int n1,int n2);
 int main()
 {
 int num1 = 10;
 int num2 = 20;
 int result;
 int *(*ptr)(int,int);
 ptr = &sum;
 result = (*ptr)(num1,num2);
 printf("Addition : %d",result);
 return(0);
 }
int sum (int n1,int n2)
{
return(n1 + n2);
}

Explanation :

  • Write whole program using normal function call i.e sum(num1,num2);
  • After you write whole code, just erase line in which we have called function and replace that line with following line -

Step 1 : Declaring Pointer Variable

int *(*ptr)(int,int);

means -

Declare pointer variable which is capable of storing
address of function which have integer as return type
and which takes 2 arguments.

Step 2 : Initializing function Pointer

ptr = &sum;
  • Store address of function in Function Pointer

Step 3 : Calling Function

result = (*ptr)(num1,num2);

It will call function sum(num1,num2);
above statement will be elaborated as -

result = (*ptr)(num1,num2);
result = (*&sum)(num1,num2);
result = (*&sum)(num1,num2);
result = (sum)(num1,num2);
result = sum(num1,num2);

R-Value in Expression : C Programming

In the previous chapter we have learnt about the Lvalue of an expression in this chapter we are going to learn R-value of an expression.

What is R-Value ?

  1. R Value stands for Right value of the expression.
  2. In any Assignment statement R-Value must be anything which is capable of returning Constant Expression or Constant Value.
  3. R Value Can be anything of following -
Examples of R-Value
Variable Constant
Function Macro
Enum Constant Any other data type

Diagram Showing Lvalue :

Example of RValue :

#include<stdio.h>
int main()
{
int num;
num = 5;
return(0);
}

In the above example, Constant Value 5 is assigned to the variable will be considered as right Value of the variable.

Important Tips of Using RValue :

Tip 1 : R Value may be Constant or Constant expression

num = 20;      //Constant RValue
num = 20 + 20; //Constant Expression as RValue
  1. In the example, we have assigned constant value to the variable.
  2. Constant value “20” is considered as RValue.
  3. In the next line we have assigned constant expression to the variable. “20 + 20” will be evaluated first and then result of expression will be assigned to an Variable.

Tip 2 : R Value may be MACRO

#define MAX 20
main() {
   int num = MAX;
}

If we have defined a MACRO then we can use MACRO as right value. In the above example we have assigned the 20 to the variable “num”.

In case if we defined the MACRO value of different data type then it may results into compile error.

Tip 3 : R Value may be Variable

#define MAX 20
main() 
{
   int flag = 0;
   int num  = flag;
}

For more information , Visit MSDN library.

L-Value in Expression : L-value require Error [Solved]

What is LValue ?

  1. Lvalue stands for left value and Expressions that refer to memory locations are called “l-value” expressions.
  2. In any Assignment statement L-Value must be a container ( i.e. which have ability to hold the data)
  3. Variable is the only container in C thus L Value must be any Variable.
  4. L Value Cannot be Constant,Function or any of the available data type in C

Diagram Showing Lvalue :

Example of LValue :

#include<stdio.h>
int main()
{
int num;
num = 5;
return(0);
}

In the above expression, Constant value 5 is being assigned to a variable ‘num’. Variable ‘num’ is called as storage region’s , ‘num’ can considered as LValue of an expression.

Important Concepts about : LValue of an Expression

Tip 1 : Lvalue cannot be a Constant

int main()
{
int num;
5 = num;  //Error
return(0);
}

Tip 2 : Lvalue cannot be a Constant Variable

int main()
{
const num;
num = 20;  //Error
return(0);
}

Tip 3 : Lvalue cannot be a MACRO

#define MAX 20
int main()
{
MAX = 20;  //Error
return(0);
}

Tip 4 : Lvalue cannot be a Enum Constant

enum {JAN,FEB,MARCH};
int main()
{
JAN = 20;  //Error
return(0);
}

Tip 5 : Lvalue cannot be a Data Type

#define<stdio.h>
#define max 125
struct book{
  char *name;
  int  pages;
};
void main()
{
book = {"C Programming",100};
}

How to solve this error : L-Value Require error ?

Causes of Error :

  1. Whenever we are trying to assign value to constant value
  2. Whenever we are trying to increment or decrement Constant Expression
  3. Inside if statement , if we try to write comparison operator as “= =” instead of ”==”, then we will get this error.

Solution :

Solution to this problem is very simple -

Always try to assign constant value to “Variable“. If you are using comparison operator then we don’t provide space in between operators.
In the next chapter we will be learning RValue of an expression which is also called as right value of an expression.

Question 3: What is the difference between constant to pointer and pointer to constant?

What is the difference between constant to pointer and pointer to constant?


No Pointer to Constant Constant Pointers
1 *ptr = 20 Statement is Invalid in Pointer to Constant i.e Assigning Value is Illegal *ptr = 20 is Absolutely Valid in Constant Pointers i.e Assigning Value is Perfectly legal
2 ptr ++ Statement is Valid in Pointer to Constant ptr ++ Statement is Invalid in Constant Pointers
3 Pointer Can be Incremented and Decremented Pointer Cannot be Incremented and Decremented
4 Pointer is Pointing to Constant Data Object Constant Pointer is Pointing to Data Objects
5 Declaration : const int *ptr ; Declaration : int * const ptr ;