#pragma directive in C : Implementation-specific directives Syntax: #pragma <directive name> Explanation : With #pragma, Turbo C++ can define whatever directives it desires without interfering with other compilers that support #pragma. If the compiler doesn’t recognize <directive name>, it ignores the #pragma directive without an error or warning message. Turbo C++ supports the following #pragma directives: #pragma(…)
#undef : Undefine Macro (Preprocessor Directive in C Programming)
#undef : Preprocessor Directive in C Programming Syntax: #undef <identifier> #undef : Undefines a symbol Undefines a symbol specified by <identifier> which was previously defined with a #define directive. #undef Directive is used to undefine any Macro Symbol. #undef can undefine only “User Defined” Macro’s. #undef cannot undefine “Global Macro Identifiers“. #undef is used where we(…)
#ifndef statement : Conditional Compilation Directives (C Preprocessor)
#ifndef statement : Conditional Compilation Directives (C Preprocessor) What it does ? These Conditional Compilation Directives allow us to include certain portion of the code depending upon the output of constant expression Block is Called as Conditional Group Syntax : #ifndef MACRONAME Statement_block; #endif Explanation : If the MACRONAME specified after #ifndef is not defined(…)
#ifdef statement : Conditional Compilation Directives (C Preprocessor)
#ifdef statement : Conditional Compilation Directives (C Preprocessor) What it does ? These Conditional Compilation Directives allow us to include certain portion of the code depending upon the output of constant expression Block is Called as Conditional Group Syntax : #ifdef MACRONAME Statement_block; #endif Explanation : If the MACRONAME specified after #ifdef is defined previously(…)
#elif statement : Conditional Compilation Directives (C Preprocessor)
#elif statement : Conditional Compilation Directives (C Preprocessor) What it does ? These Conditional Compilation Directives allow us to include certain portion of the code depending upon the output of constant expression Syntax : #if Expression1 Statement_block 1; #elif Expression2 Statement_block 2; #elif Expression3 Statement_block 3; #else Statement_block 4; #endif Explanation : Expression allows only(…)
#else statement : Conditional Compilation Directives (C Preprocessor)
#else statement : Conditional Compilation Directives (C Preprocessor) What it does ? These Conditional Compilation Directives allow us to include certain portion of the code depending upon the output of constant expression Syntax : #include<stdio.h> #define NUM 11 void main() { #if((NUM%2)==0) printf(“\nNumber is Even”); #else printf(“\nNumber is Odd”); #endif } Explanation : Expression allows (…)
#if statement : Conditional Compilation Directives (C Preprocessor)
#if statement : Conditional Compilation Directives (C Preprocessor) What #if statement do ? These Conditional Compilation Directives allow us to include certain portion of the code depending upon the output of constant expression Syntax : #if Expression Statement 1 Statement 2 . . Statement n #endif Explanation : #if Statement Expression allows only constant expression(…)
Difference between macro and function in C Programming
Difference between macro and function No Macro Function 1 Macro is Preprocessed Function is Compiled 2 No Type Checking Type Checking is Done 3 Code Length Increases Code Length remains Same 4 Use of macro can lead to side effect No side Effect - 5 Speed of Execution is Faster Speed of Execution is Slower(…)
Fgetc function : Get character from stream (stdio.h)
Fgetc function : get character from stream What this function does ? Header File : Stdio.h fgetc gets a character from a stream fgetc returns the next character on the named input stream. It is a function not macro (getc is a macro) Return Value : Event Return Value On Error Returns Character read after(…)
What is RValue ?
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 ? R Value stands for Right value of the expression. In any Assignment statement R-Value must be anything which is capable of returning Constant Expression or Constant(…)
What is L-Value in Expression | L-value require Error !!
What is LValue ? Lvalue stands for left value and Expressions that refer to memory locations are called “l-value” expressions. In any Assignment statement L-Value must be a container ( i.e. which have ability to hold the data) Variable is the only container in C thus L Value must be any Variable. L Value Cannot(…)
Rules For Constructing Variable Name | Identifier Naming Rules
Rules For Constructing Variable Name Characters Allowed : Underscore(_) Capital Letters ( A - Z ) Small Letters ( a - z ) Digits ( 0 - 9 ) Blanks & Commas are not allowed No Special Symbols other than underscore(_) are allowed First Character should be alphabet or Underscore Variable name Should not be Reserved Word Explanation with Example(…)
Fundamental Attributes of Variable in C Programming
Fundamental Attributes of C Variable : Name of a Variable Value Inside Variable Address of Variable Size of a Variable Type of a Variable 1.Name of Variable We can Give proper name to any Variable which is human readable. Compiler won’t understand this name , This is only for human understanding. Variable name is only(…)
Macro Taking Argument in C | Argumented Macro Preprocessor inC Programming
Pre-processor Macro taking Argument : Argumented Macro (Macro having Arguments) Everytime whenever the macro name is encountered , the arguments are replaced by the actual arguments from the program. Macroname having Arguments is called Argumented Macro. Argumented macro is as called as function macro as it looks like calling function. Advantages of Argumented macro :(…)
Preprocessor Directive MCQ 1 : Pre Incrementing Macro
Guess What will be the output of following Code Snippet - #include<stdio.h> #define MAX 10 int main(){ int num; num = ++MAX; printf(“%d”,num); return 0; } Options : 10 11 Compile Error Run-time Error Compile Error Explanation : num = ++MAX; will be expanded as - num = ++10; = Compile Error Macro Preprocessor only(…)
Nested Preprocessor Macro directive having Arguments in C Programming
How to use Nested Macro ? These are Macros having Arguments Every time whenever the macro name is encountered , the arguments are replaced by the actual arguments from the program. Macro name within another macro is called Nesting of Macro. Use of Nested Macro : #define CUBE(x) (SQU(x)*x) Live Example : #include<stdio.h> #define SQU(x)((x)*x)(…)
#define Preprocessor Directive in C | Simple Substitution Macro
Simple Substitution Macro : #define Preprocessor in C Syntax #define macro_identifier value Note #define Preprocessor defines a identifier and a value that is substituted for identifier each time it is encountered in the source file Generally macro-identifier is written in the Capital Letter to distinguish it from other variables. Its like a name-value Pair. Examples(…)
What Pre-processor Directive do ? | Tasks Performed by Preprocessor Directive
Tasks Performed by Preprocessor Directive | What Pre-processor Directive do ? What is Preprocessor : Program that Processes or Analyzes the source code file before Given to the Compiler is called as Pre-Processor Refer this Article to know better : [ What is preprocessor? ] Tasks Performed by Pre-processor Directive in C Replaces Trigraph Sequences Joins any(…)
How C Processor Works | Processing of Preprocessor Directives with Flowchart
We all know that preprocessor comes before compiler so complete source code will be first processed by the preprocessor and then output will be given to the compiler. How C Processor Works | Processing of Preprocessor Directives with Flowchart following flowchart clearly explains the working of Pre-processor Directive - Explanation of Working : Step 1(…)
File Inclusive Directives >> C Preprocessor Directives
File Inclusive Directives File inclusive Directories are used to include user define header file inside C Program. File inclusive directory checks included header file inside same directory (if path is not mentioned). File inclusive directives begins with #include If Path is mentioned then it will include that header file into current scope. Instead of using triangular brackets(…)
Tasks Performed By Pre-processor
Preprocessor : Program that Processes or Analyzes the source code file before Given to the Compiler Tasks Performed By Pre-processor : Replaces Trigraph Sequences Joins any Line with the Backslash Character into Single Line Divide Program into Set of Tokens Expand Macroes Remove Comments and Replace it by Single Space Represent the Escape Sequence by(…)
C Interview Question Puzzle : Sizeof Operator is not Applicable to Function
Must Read Tip To Solve Following Problem : First one must understand that - sizeof is not an function it’s an operator. Inside C Program we can calculate size of all data types including user defined and in built data types. However Sizeof Operator cannot calculate Size when we pass function name as parameter. However(…)
C Interview Question Puzzle : Main Returns Non-Zero Value
Must Read Tip To Solve Following Problem : The Main Always returns positive Value. Inside C Program Function is nothing but set of instructions combined together in a single block. Function Block may have certain starting address. This Address gets printed when we try to print function name inside printf statement. Example : printf(“%d”, main);(…)
How to Run C Program Using Command Prompt inside Window Operating System?
Introduction :C Program can be run using Command Prompt .We can use MS-DOS to run c Program. Every window OS comes with inbuilt Command Prompt. So we are going to use this command prompt to run our c program. Pre-requisite : Window’s Command Prompt Turbo C/C++ Compiler Why we should run C Program using Command(…)
Get System Date : _dos_getdate() >> dos.h
Gets DOS system date in C Programming : void _dos_getdate(struct dosdate_t *datep); dosdate_t Structure and Structure Members : struct dosdate_t { unsigned char day; /* 1-31 */ unsigned char month; /* 1-12 */ unsigned int year; /* 1980-2099 */ unsigned char dayofweek; /* 0-6; 0 = Sunday */ }; This structure is used by _dos_getdate()(…)
Integer Data Type : About Short Integer & Long Integer
Integer Data Type : About Short Integer & Long Integer Integers are whole numbers with a wide range of values that are machine dependent. Integer occupies 2 bytes memory space and its value range limited to -32768 to +32767 How this range is Calculated ? Size of Integer = 2 bytes No of Bits =(…)
Different Ways of Formatting Printf in C
Different Ways of Formatting Printf in C 1.Display Normal Message printf(“Hello Welcome to C”); 2.Display Space printf(“\t”); 3.Display New Line printf(“\n”); 4.Printing Value of Variable printf(“Addition of two Numbers : %d”,sum”); 5.Multiple Format Specifiers printf(“I Love %c %s”,’c',”Programming”); Output : I Love c Programming 6.Display Integer In Different Styles (- is space) printf(“%d”,1234); printf(“%3d”,1234); printf(“%6d”,1234);(…)
Are ++*ptr and (*ptr)++ are same ?
Question : Are ++*ptr and (*ptr)++ are same ? Answer : Yes ++*ptr Increments the Value being Pointed to by ptr Suppose ptr is Pointing to the Integer Variable having value 10. [ num = 10 ] Now ++*ptr Results in 11 (*ptr)++ means Grab the Value of (*ptr) And then Increment It , which(…)
How to Reverse a String : Presentation Slide Show
What is the return value from printf() function?
What is the return value from printf() function? Printf Statement is used to Print Something on Console (On Screen). Printf is Predefined function is C Programming Language. Printf Statement always returns Integer Value. Live Example : Return Value of Printf #include<stdio.h> void main() { int a=20; printf(“%d”,printf(“%d%d%d”, a,a,a)); } Output : 20 20 208 Why(…)
C Programming Puzzle : Switch and Variable name Validity
C Programming Puzzle : Switch and Variable name Validity This Program at a First Glance is error Free but It has one Serious Bug , Will you remove it without compiling it ? #include<stdio.h> void OS_Solaris_print() { printf(“Solaris - Sun Microsystemsn”); } void OS_Windows_print() { printf(“Windows - Microsoftn”); } void OS_HP-UX_print() { printf(“HP-UX - Hewlett(…)
C Printf Puzzle 1 : Guess value of X : “Hello World”
Printf Puzzle : Guess what should X be replaced with so as to get output as “Hello World“ #include<stdio.h> void main() { if(X) { printf(“Hello”); } else { printf(“World”); } } Way1 : Output #include<stdio.h> void main() { if(printf(“Hello”)-5) { printf(“Hello”); } else { printf(“World”); } } Explanation of the Program : Printf Returns Number(…)
Syntax : Do While Loop in C Programming
Do-While Loop Syntax : initialization; do { ————- ————- ————- ————- incrementation; }while(condition); Note : It is Exit Controlled Loop. Initialization , Incrementation and Condition steps are on different Line. It is also called Bottom Tested [i.e Condition is tested at bottom and Body has to execute at least once ]
Syntax : While Loop in C Programming
While Loop Syntax : initialization; while(condition) { ———- ———- ———- ———- ———- —— incrementation; } Note : For Single Line of Code - Opening and Closing braces are not needed. while(1) is used for Infinite Loop Initialization , Incrementation and Condition steps are on different Line. While Loop is also Entry Controlled Loop.[i.e conditions are(…)
Syntax : For Loop in C Programming
For Loop Syntax : for(initialization ; conditional ; increment) { ——- ——- //body ——- ——- } Note : For Single Line of Code - Opening and Closing braces are not needed. There can Exist For Loop without body. Initialization , Incrementation and Condition steps are on same Line. Like While loop , For Loop is(…)
Syntax : Continue Statement in C Programming
Continue Statement : loop { continue; //code } Note : It is used for Skipping part of Loop. Continue causes the remaining code inside a loop block to be skipped and causes execution to jump to the top of the loop block Loop Use of Continue !! for while do-while
Syntax : break Statement in C Programming
Break Statement Simply Terminate Loop and takes control out of the loop. Break in For Loop : for(initialization ; condition ; incrementation) { Statement1; Statement2; break; } Break in While Loop : initialization ; while(condition) { Statement1; Statement2; incrementation break; } Break Statement in Do-While : initialization ; do { Statement1; Statement2; incrementation break; }while(condition);(…)
Syntax : Goto Statement in C Programming
Goto Statement goto label; ——- ——- label : Whenever goto keyword encountered then it causes the program to continue on the line , so long as it is in the scope . Types of Goto : Forward Backward Note :
Syntax : If Statement in C Programming
If Statement : if(conditional) { Statement No 1 Statement No 2 Statement No 3 . . . Statement No N } Note : More than One Conditions can be Written inside If statement. Opening and Closing Braces are required only when “Code” after if statement occupies multiple lines. if(conditional) Statement No 1 Statement No 2(…)
Syntax : If-else Statement in C Programming
If-Else Statement : if(conditional) { //True code } else { //False code } Note : Consider Following Example - int num = 20; if(num == 20) { printf(“True Block”); } else { printf(“False Block”); } If part Executed if Condition Statement is True. if(num == 20) { printf(“True Block”); } True Block will be executed(…)
How to Run C Program in Linux Environment ?
How to Run C Program in Linux Environment ? Step 1 : Open Any Text Editor in Linux . Step 2 : Type this Following Snippet in Editor. #include<stdio.h> int main() { printf(“Hello , Welcome to Linux Environment”); return(0); } Step 3 : Save this Program by .C extension. [Say above program as hello.c ](…)
C Program to draw Diode Symbol Using Graphical Functions
Program : Draw Diode Symbol Using Graphical Functions #include<stdio.h> #include<conio.h> #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,”c:\\tc\\bgi”); line(100,100,100,200); //Vertical Line line(70,150,100,150); //Middle Line Dividing Vertical Line line(100,100,150,150); //Slant Line From Top to Bottom line(100,200,150,150); //Slant Line From Bottom to Top line(150,100,150,200); //Vertical Line line(150,150,250,150); //Horizontal Line getch(); closegraph(); } Diode :
Common Mistakes in C : Printf Errors
1 : Missing Comma . Comma is missing between format specifier(“%d”) and Variable (number). Error message : ” Function call missing )“ #include<stdio.h> void main() { int number = 10; printf(“%d”number); //Error it should be written as : printf(“%d”,number); } 2 : Write Correct Spelling of printf. By mistake , many beginners misspelled “printf” as(…)
Common Pointer Mistakes in C Programming
5 Common Pointer Mistakes in C Programming that should be avoided by each programmer. Learn how to avoid common silly mistakes while using pointer,
Common Mistakes in C : Decision Making Errors
Decision making : if-else,else if ladder Errors Mistake 1 : Assignment Operator & Comparison Operators Assignment Operator (=) is used for assigning value to variable Comparison Operator (==) checks whether LHS and RHS entries are same or not In if statement Use “==” instead of “=” if(var = 10) { //Statement 1 //Statement 2 //Statement(…)
Common Mistakes in C : Scanf Errors
Common Mistakes : Scanf Errors 1 : Don’t forget to write “&” before variable name #include<stdio.h> void main() { int num; //Incorrect Way : scanf(“%d”,num); scanf(“%d”,&num); } Syntactically it won’t show any error message Logically It shows you “Garbage” or “Unexpected Value”. “&” should be written before “Variable” name . 2 : Don’t write “&”(…)
Common Mistakes in C Programming : 1-D Array Errors
Some Common Mistakes in C Programming while using 1-Dimensional Array. Silly Mistakes by novice programmer regarding 1-D array are listed in this article.
Parameter Passing Sequence of Printf in GCC and Turbo C
Que : Parameter Passing Sequence In GCC #include<stdio.h> int main() { int a=10; printf(“%d%d%d”,a++,a++,++a); return 0; } Output : In Linux 12 11 13 In Window 12 11 11 Explanation : In Turbo C / Window Paramters are Passed from Right to Left in Printf Statement. In Linux This Scheme is different.
How to Run C Program in Linux Environment
Note : This tutorial is for those who used to write programs in Windows Environment and want to write programs in Linux Environment. Steps : 1.Write Program You can type C program using any of the editors that are available under Linux. VI and EMACS are two famous editors in Linux. I have Written Sample(…)
What is ANSI ?
ISO : International Standard OrganizationANSI : American National Standard Institute.de facto Standards : [ Definition from Wikipedia ] De facto is a Latin expression that means “by [the] fact”. In law, it is meant to mean “in practice but not necessarily ordained by law American National Standards Institute [ ANSI ] Founded in 1918(…)