100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Lecture notes

Computer system

Rating
-
Sold
-
Pages
20
Uploaded on
24-07-2023
Written in
2017/2018

Computer system, computer science, computer skills, computer language











Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
July 24, 2023
Number of pages
20
Written in
2017/2018
Type
Lecture notes
Professor(s)
Prof
Contains
All classes

Subjects

Content preview

#include<stdio.h>

#include add.c

void main()

{

void add(); //FUNCTION PROTOTYPE/ DECLARATION.

add(); //FUNCTION CALLING

}

The file add1.c contains the function definition as follows.

void add()

{

int a,b,c;

printf(“enter two numbers”);

scanf(%d%d”,&a,&b);

c=a+b;

printf(“c value is:%d”,c);

}

3 : CONDITIONAL COMPILATION DIRECTIVES : C preprocessor also supports number
of conditional compilation directives as



1 : #undef : Undefined a macro

2 : #ifdef : Tests for a macro definition.

3 : #endif : Specifies the end of #if.

4 : #if : Tests compile-time condition.

5 : #else : Specifies alternative when #if test fails.

These are used to select a particular segment of code for compilation depending on the
condition.

C PROGRAMMING Page 191

,EXAMPLE PROGRAM FOR CONDITIONAL COMPILATION DIRECTIVES:

A) EXAMPLE PROGRAM FOR #IFDEF, #ELSE AND #ENDIF IN C:

 “#ifdef” directive checks whether particular macro is defined or not. If it is defined, “If”
clause statements are included in source file.

 Otherwise, “else” clause statements are included in source file for compilation and
execution.

Ex:

#include <stdio.h>

#define RAJU 100

int main()

{

#ifdef RAJU

printf("RAJU is defined. So, this line will be added in " \

"this C file\n");

#else

printf("RAJU is not defined\n");

#endif

return 0;

}

OUTPUT:

RAJU is defined. So, this line will be added in this C file



B) EXAMPLE PROGRAM FOR #IFNDEF AND #ENDIF IN C:

 #ifndef exactly acts as reverse as #ifdef directive. If particular macro is not defined, “If”
clause statements are included in source file.

 Otherwise, else clause statements are included in source file for compilation and
execution.

C PROGRAMMING Page 192

, Ex:
#include <stdio.h>
#define RAJU 100
int main()
{
#ifndef SELVA
{
printf("SELVA is not defined. So, now we are going to " \
"define here\n");
#define SELVA 300
}
#else
printf("SELVA is already defined in the program”);

#endif
return 0;

}
OUTPUT:

SELVA is not defined. So, now we are going to define here

C) EXAMPLE PROGRAM FOR #IF, #ELSE AND #ENDIF IN C:

 “If” clause statement is included in source file if given condition is true.

 Otherwise, else clause statement is included in source file for compilation and execution.

Ex:

#include <stdio.h>
#define a 100
int main()
{
#if (a==100)
printf("This line will be added in this C file since " \
"a \= 100\n");
#else
printf("This line will be added in this C file since " \
"a is not equal to 100\n");
#endif
return 0;
}


OUTPUT:
This line will be added in this C file since a = 100

C PROGRAMMING Page 193
£16.29
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
akhilagouri

Get to know the seller

Seller avatar
akhilagouri A Level Notes
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
107
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions