Programming: Structures
Programming: Structures
PROGRAMMING AND
DATA STRUCTURES
Question/Answer (Set 1)
NESO ACADEMY
#include <stdio.h>
int main() {
printf("%d", print f("%s", "Hello World!") );
return 0;
"CAUsers\jaspr\ Downloads\C programs of dennis ritchie\questions-an
NESOACADEMY
#include <stdio.h>
a) 265
b) Some characteraccording to ASCIl table
c)7
d 9
NESO ACADEMY
Q4: Which of the following statement/statements is/are
correct corresponding to the definition of integer:
I. signed int i;
a) Only land V are correct
Il. signed i;
b) Only is correct
l
NESO ACADEMY
Q5: What does the following progranm fragment prints?
int main() { a) garbage
unsigned i = 1; b) -3
int j= -4;
printf("%u", i+j);
return 0; ) Integer value depends
machine tomachine
None of theabove
from
-3 in 2s complement representation:
Step 1: Take 1s complement of3
3=00000000 00000000 00000000 00000011
1s complement of 3=111 11111 n00
Step 2: Add 1 to the result. It will give
111111 111 111111 1111101 = 4294967293 (on my computer)
NESO ACADEMY
DEFINING ScOPE
Scope = Lifetime
NESO ACADEMY
#include <stdio. h>
int main() {
Gnt var = 34; Scope of this variable is within
printf("%d", var); main0 function only. Therefore
return ; called LOCAL to main) function.
int fun()
{ Contents of
this block is
NESO ACADEMY
#include <stdio.h> #include <stdio .h>
int main(),{
int main() { int var = 3;
int var = 3;
int var = 4; {
int var = 4;
printf("%d\n", var); printf("%d\n", var);
printf("%d", var); }
return 0; printf("%d", var);
return 0;
#include <stdio. h>
int fun();
int main() {
int var = 3;
printf("%d\n", var; Output: 3
fun()
return 0;
Output: 10
int fun(O
PROGRAMMING AND
|DATASTRUCTURES
Modifiers -auto and extern
NESO ACADEMY
WHAT IsAUTO MODIFIER?
Auto means Automatic
Variables declared inside a scope bydefault are automatic variables.
int main() {
auto int var;
printf("%d", var);
return 0;
#include <stdio.h>
int var;
int main() {
printf( "%d", var};
return O;
ExTERN MODIFIER
NESO ACADEMY
main.c xother.c x
int a 57
2 int a
& others
4include <stdio.h>
3 extern int a:
int main ()
5
6
7
printf ("$d", a)
return 0:
: BCUsersjaspr\Documentslmy, program_ 1\bin\ Debuglmy.program_1.exe
1
6include <stdio.h>
2
3 extern int a;
4 extern inh
5 extern int a;
6 int main () ClUsersljaspr\Documents\imy, program_ 1\bin\Debugimy program_1.exe
5
8| printf ("%d", a)
return
; Process returned e (exe) execution time : e.430 s
0:
10 Press any key to continue.
11
other.c
7
8
printf ("%d", a)
return 0;
: 9
Process returned e (exe)execution time :e.358 s
9 Press any key to continue.
10
NESO ACADEMY
C
PROGRAMMING AND
DATA STRUCTURES
Modifier -register
NESO ACADEMY
Register
Memory
Magnetic Disks
Auxillary
Memory
Magnetic Tapes
#include <stdio.h>
int main() {
register int var;
return 0;
WHAT ISREGISTER MODIFIER?
PROGRAMMING AND
DATA STRUCTURES
Modifier -static
NESO ACADEMY
"main.c add.c
x
1 int increment ()
int count 0:
count count + li
5 return count
A Code::Blocks x9 Search results x Ccc xO Build log xBuild messages x CpoCheck x opCheck messages x Cscope xDebugger
Management
main.c x add.cx
Projects Symbols
#include <stdio.h>
oWorkspace 2 #include <stdlib.h>
3
Smy-project1
Sources
add.c
main.c
4
5 {int main ()
int value:
value = increment ()
CUsersjaspr\Documentsimy-project1\bin\ Debugimyproject1.exe
0;
13
14
C:\Users\jaspr\Documents \my-projectl\main.c:
C: \Usera \ja spr\Documen ts \my-projectl \ma in.c:
=
7}
value increment ()
1 int count
2
3 int increment ()
4 P{
5 count count + li
6 return count
7
8
main.c x add.c x
1 4include <stdio.h>
2 #include <stdlib.h>
3
4
5
6
{ int main()
10
value increment :
() Press any key to continue.
1 #include <stdio.h>
2 #$include <stdlib.h>
3
4
5
6
{ int main ()
10
value increment (): Press any key to continue.
13
14
int increment ()
count = count + 1:
return count
main.c "add.c
1 static int count
2
4P
5
int increment ()
count count + l:
6 return count
2
1 #include <stdio h> .
#include <stdlib.h>
Code::Blocks x9 Search results x Cccc xBuildlog Build messages CppCheck xCppCheck messages xACscope x Debugger
x
Management add.cX
main.c x
Projects Symbols
#include <stdio.h>
OWorkspace 2 #include <stdlib.h>
Smy-projectt 3
e Sources
-Oadd.c
main.c
4
5
6
8
{Wextoern
int main
int count:
()
int value:
value =
increment () :: 3
C\UsersljaspnDocuments\my-project1\bin\Debugimy-project1.exe
-Dadd.c
main.c
4
5
6
7
8
{wextern int counts
int main ()
int value:
value = increment ()
3
D c\Usersljasp\ Documents\my project1\bin\Debug\my project1.exe
NESO ACADEMY