Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 3 fuera de 20 páginas
Notas de lectura

Computer system

Document preview thumbnail
Vista previa 3 fuera de 20 páginas

Computer system, computer science, computer skills, computer language

Vista previa del contenido

#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

Información del documento

Nivel de Estudio
Tema
Subido en
24 de julio de 2023
Número de páginas
20
Escrito en
2017/2018
Tipo
Notas de lectura
Profesor(es)
Prof
Contiene
Todas las clases
$22.89

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
107
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes