SlideShare a Scribd company logo
Q4/Define the Following C Keywords ?
#define?? #include?? #pragma?? #asm?? #ifdef...#endif?
o #define ……………………………….
o #include …………………….
#pragma ………………………..
o #asm ………………………………….
o #ifdef ………………………………………
o #endif ……………………………………………
1
Pointers Quiz
Q1/What is the stack?
And what is the output from this code?
#include "stdio.h"
int* func ()
{
int a = 5 ;
int *pa = &a ;
return pa ;
}
int main ()
{
int x = 10 ;
int* ptr ;
ptr = func ();
printf ("%d", *ptr+x);
return 0 ;
}
Q2/ write C Code to Count number of bits to
be flipped to convert A to B ?
The same question bin another shape
Write C code to determine how many
different bits between two integers?
Example :
Input : a = 10, b = 20
Output : 4
Binary representation of a is 00001010
Binary representation of b is 00010100
We need to flip highlighted four bits in a
to make it b.
Input : a = 7, b = 10
Output : 3
Binary representation of a is 00000111
Binary representation of b is 00001010
We need to flip highlighted three bits in a
to make it b.
Q3/ Complete the following statement
global variables -------> data memory
static variables -------> ……
constant data types -----> ……………..……………………….,
local variables(declared and defined in functions) --------> ……
variables declared and defined in main function -----> …..
pointers(ex: char *arr, int *arr) -------> ………………………………...
dynamically allocated space(using malloc, calloc, realloc) --------> ……………………..
Q5/Using the variable a, give definitions for the following:
a) An integer
b) A pointer to an integer
c) A pointer to a pointer to an integer
d) An array of 10 integers
e) An array of 10 pointers to integers
f) A pointer to an array of 10 integers
g) A pointer to a function that takes an integer as an argument and returns an integer
h) An array of ten pointers to functions that take an integer argument and return an
integer
5
5
7
50
8
5
Name: ………………………..
2
Q6/Embedded systems are often characterized by requiring the programmer to access
a specific memory location. On a certain project it is required to set an integer
variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure
ANSI compiler. Write code to accomplish this task
Q8/ For (intelligent Embedded Engineers)
Write a Best C Code to implement this example by
Using Pointers, Union and Bitfields in C
programming and can access address “0x00008000”
1. individual bits of a memory location (1 Byte).
or
2. Read/write on all the memory block (1 byte)
Memory
0x00008000
1 Byte
bit012bit34bit5bit6
bit7
reserved
For example.,
/*
* main.c
*
* Created on: Jun 16, 2017
* Author: Keroles Shenouda
*/
int main()
{
int i;
int arr[4] = {10, 20 ,30, 40};
int arr_size =
sizeof(arr)/sizeof(arr[0]);
for (i = 0; i < arr_size; i++)
printf("%d ", arr[i]);
fun(arr);
return 0;
}
#include<stdio.h>
void fun(int arr[])
{
int i;
int arr_size = sizeof(arr)/sizeof(arr[0]);
for (i = 0; i < arr_size; i++)
printf("n %d ", arr[i]);
}
Q7/what is the output
3
8
10
3
Q1/The Stack
What is the stack? It's a special region of your computer's memory that stores temporary variables
created by each function (including the main() function). The stack is a "LIFO" (last in, first out) data
structure, that is managed and optimized by the CPU quite closely. Every time a function declares a new
variable, it is "pushed" onto the stack. Then every time a function exits, all of the variables pushed
onto the stack by that function, are freed (that is to say, they are deleted). Once a stack variable is
freed, that region of memory becomes available for other stack variables.
The advantage of using the stack to store variables, is that memory is managed for you. You don't have
to allocate memory by hand,
Q3/ Complete the following statement
global variables -------> data memory
static variables -------> data
constant data types -----> (depends on the compiler).For example, in
the GCC compiler, on most machines, read-only variables, constants,
and jump tables are placed in the text section.
local variables(declared and defined in functions) --------> stack
variables declared and defined in main function -----> stack
pointers(ex: char *arr, int *arr) -------> heap or data or stack,
depending on the context. C lets you declare a global or a static pointer,
in which case the pointer itself would end up in the data segment.
dynamically allocated space(using malloc, calloc, realloc) --------> heap
Q2/
// Count number of bits to be flipped
// to covert A into B
#include <iostream>
using namespace std;
// Function that count set bits
int countSetBits(int n)
{
int count = 0;
while (n)
{
count += n & 1;
n >>= 1;
}
return count;
}
// Function that return count of
// flipped number
int FlippedCount(int a, int b)
{
// Return count of set bits in
// a XOR b
return countSetBits(a^b);
}
// Driver code
int main()
{
int a = 10;
int b = 20;
cout << FlippedCount(a, b)<<endl;
return 0;
}
Q4/Define the Following C Keywords ?
#define?? #include?? #pragma?? #asm?? #ifdef...#endif?
o #define define a macro
o #include include a source file
o #pragma is for compiler directives that are machine specific or
operating system specific, i.e. it tells the compiler to do something,
set some
option, take some action, override some default, etc. that may or
may not apply
to all machines and operating systems.
o #asm to include the assembly directive
o #ifdef compile these lines if NAME is not defined
o #endif to delimit the scope of these directives
Pointers Quiz Solution
4
Q5/
The answers are:
a) int a; // An integer
b) int *a; // A pointer to an integer
c) int **a; // A pointer to a pointer to an integer
d) int a[10]; // An array of 10 integers
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and
returns an integer
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer
argument and return an integer
Q6/
int *ptr;
ptr = (int *)0x67a9;
*ptr = 0xaa55;
A more obscure approach is:
*(int * const)(0x67a9) = 0xaa55;
Q8/
/*
* main.c
*
* Created on: Jun 16, 2017
* Author: Keroles Shenouda
*/
#include "stdio.h"
struct Sbits {
unsigned char bit012:3;
unsigned char bit34:2;
unsigned char bit5:1;
unsigned char bit6:1;
unsigned char bit7:1;
} status;
union registerType
{
unsigned char Byte;
struct Sbits bits ;
};
int main ()
{
// define a pointer and cast it to point to the registers memory
location
union registerType *pReg = (union registerType*)0x00008000;
// use the fields as
pReg->bits.bit5 = 1;
pReg->bits.bit012 = 7;
// access the whole byte as
pReg->Byte = 0x55;
return 0 ;
}
Explanation:
The first printf will print 10 20 30 40
The second printf will print 10
The Explanation
In C, array parameters are always treated
as pointers. So following two statements
have the same meaning.
void fun(int arr[])
void fun(int *arr)
[] is used to make it clear that the
function expects an array, it doesn’t
change anything though. People use it
only for readability so that the reader is
clear about the intended parameter type.
The bottom line is, sizeof should never be
used for array parameters, a separate
parameter for array size (or length)
should be passed to fun(). So, in the
given program, arr_size contains ration of
pointer size and integer size, this ration=
is compiler dependent.
Q7/

More Related Content

What's hot

C programming session8
C programming  session8C programming  session8
C programming session8
Keroles karam khalil
 
Embedded c programming
Embedded c programmingEmbedded c programming
Embedded c programming
PriyaDYP
 
Lecture 2 verilog
Lecture 2   verilogLecture 2   verilog
Lecture 2 verilogvenravi10
 
C programming session5
C programming  session5C programming  session5
C programming session5
Keroles karam khalil
 
C programming session7
C programming  session7C programming  session7
C programming session7
Keroles karam khalil
 
First session quiz
First session quizFirst session quiz
First session quiz
Keroles karam khalil
 
C programming session3
C programming  session3C programming  session3
C programming session3
Keroles karam khalil
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
Keroles karam khalil
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
Selomon birhane
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
vvcetit
 
C programming part4
C programming part4C programming part4
C programming part4
Keroles karam khalil
 
Journey of Bsdconv
Journey of BsdconvJourney of Bsdconv
Journey of Bsdconv
Buganini Chiu
 
Assembler
AssemblerAssembler
Assembler
Jad Matta
 

What's hot (17)

C programming session8
C programming  session8C programming  session8
C programming session8
 
Embedded c programming
Embedded c programmingEmbedded c programming
Embedded c programming
 
Lecture 2 verilog
Lecture 2   verilogLecture 2   verilog
Lecture 2 verilog
 
C programming session5
C programming  session5C programming  session5
C programming session5
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Assembler
AssemblerAssembler
Assembler
 
First session quiz
First session quizFirst session quiz
First session quiz
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
Assembler (2)
Assembler (2)Assembler (2)
Assembler (2)
 
Lecture6
Lecture6Lecture6
Lecture6
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
 
C programming part4
C programming part4C programming part4
C programming part4
 
Journey of Bsdconv
Journey of BsdconvJourney of Bsdconv
Journey of Bsdconv
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 

Similar to Quiz 9

20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
eugeniadean34240
 
C++tutorial
C++tutorialC++tutorial
C++tutorialdips17
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
Atul Setu
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Embedded c programming22 for fdp
Embedded c programming22 for fdpEmbedded c programming22 for fdp
Embedded c programming22 for fdpPradeep Kumar TS
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
raghukatagall2
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
jatin batra
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
M-TEC Computer Education
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
Thierry Gayet
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
Mahmoud Samir Fayed
 
C introduction by piyushkumar
C introduction by piyushkumarC introduction by piyushkumar
C introduction by piyushkumar
piyush Kumar Sharma
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 

Similar to Quiz 9 (20)

Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
C++tutorial
C++tutorialC++tutorial
C++tutorial
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Embedded c programming22 for fdp
Embedded c programming22 for fdpEmbedded c programming22 for fdp
Embedded c programming22 for fdp
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
 
C introduction by piyushkumar
C introduction by piyushkumarC introduction by piyushkumar
C introduction by piyushkumar
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
 

More from Keroles karam khalil

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
Keroles karam khalil
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
Keroles karam khalil
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
Keroles karam khalil
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
Keroles karam khalil
 
EMBEDDED C
EMBEDDED CEMBEDDED C
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
Keroles karam khalil
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
Keroles karam khalil
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
Keroles karam khalil
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
Keroles karam khalil
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
Keroles karam khalil
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
Keroles karam khalil
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
Keroles karam khalil
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
Keroles karam khalil
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
Keroles karam khalil
 
Quiz 10
Quiz 10Quiz 10
Homework 6
Homework 6Homework 6
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
Keroles karam khalil
 
Notes part7
Notes part7Notes part7
Homework 5
Homework 5Homework 5
C programming session7
C programming  session7C programming  session7
C programming session7
Keroles karam khalil
 

More from Keroles karam khalil (20)

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
Notes part7
Notes part7Notes part7
Notes part7
 
Homework 5
Homework 5Homework 5
Homework 5
 
C programming session7
C programming  session7C programming  session7
C programming session7
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

Quiz 9

  • 1. Q4/Define the Following C Keywords ? #define?? #include?? #pragma?? #asm?? #ifdef...#endif? o #define ………………………………. o #include ……………………. #pragma ……………………….. o #asm …………………………………. o #ifdef ……………………………………… o #endif …………………………………………… 1 Pointers Quiz Q1/What is the stack? And what is the output from this code? #include "stdio.h" int* func () { int a = 5 ; int *pa = &a ; return pa ; } int main () { int x = 10 ; int* ptr ; ptr = func (); printf ("%d", *ptr+x); return 0 ; } Q2/ write C Code to Count number of bits to be flipped to convert A to B ? The same question bin another shape Write C code to determine how many different bits between two integers? Example : Input : a = 10, b = 20 Output : 4 Binary representation of a is 00001010 Binary representation of b is 00010100 We need to flip highlighted four bits in a to make it b. Input : a = 7, b = 10 Output : 3 Binary representation of a is 00000111 Binary representation of b is 00001010 We need to flip highlighted three bits in a to make it b. Q3/ Complete the following statement global variables -------> data memory static variables -------> …… constant data types -----> ……………..………………………., local variables(declared and defined in functions) --------> …… variables declared and defined in main function -----> ….. pointers(ex: char *arr, int *arr) -------> ………………………………... dynamically allocated space(using malloc, calloc, realloc) --------> …………………….. Q5/Using the variable a, give definitions for the following: a) An integer b) A pointer to an integer c) A pointer to a pointer to an integer d) An array of 10 integers e) An array of 10 pointers to integers f) A pointer to an array of 10 integers g) A pointer to a function that takes an integer as an argument and returns an integer h) An array of ten pointers to functions that take an integer argument and return an integer 5 5 7 50 8 5 Name: ………………………..
  • 2. 2 Q6/Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task Q8/ For (intelligent Embedded Engineers) Write a Best C Code to implement this example by Using Pointers, Union and Bitfields in C programming and can access address “0x00008000” 1. individual bits of a memory location (1 Byte). or 2. Read/write on all the memory block (1 byte) Memory 0x00008000 1 Byte bit012bit34bit5bit6 bit7 reserved For example., /* * main.c * * Created on: Jun 16, 2017 * Author: Keroles Shenouda */ int main() { int i; int arr[4] = {10, 20 ,30, 40}; int arr_size = sizeof(arr)/sizeof(arr[0]); for (i = 0; i < arr_size; i++) printf("%d ", arr[i]); fun(arr); return 0; } #include<stdio.h> void fun(int arr[]) { int i; int arr_size = sizeof(arr)/sizeof(arr[0]); for (i = 0; i < arr_size; i++) printf("n %d ", arr[i]); } Q7/what is the output 3 8 10
  • 3. 3 Q1/The Stack What is the stack? It's a special region of your computer's memory that stores temporary variables created by each function (including the main() function). The stack is a "LIFO" (last in, first out) data structure, that is managed and optimized by the CPU quite closely. Every time a function declares a new variable, it is "pushed" onto the stack. Then every time a function exits, all of the variables pushed onto the stack by that function, are freed (that is to say, they are deleted). Once a stack variable is freed, that region of memory becomes available for other stack variables. The advantage of using the stack to store variables, is that memory is managed for you. You don't have to allocate memory by hand, Q3/ Complete the following statement global variables -------> data memory static variables -------> data constant data types -----> (depends on the compiler).For example, in the GCC compiler, on most machines, read-only variables, constants, and jump tables are placed in the text section. local variables(declared and defined in functions) --------> stack variables declared and defined in main function -----> stack pointers(ex: char *arr, int *arr) -------> heap or data or stack, depending on the context. C lets you declare a global or a static pointer, in which case the pointer itself would end up in the data segment. dynamically allocated space(using malloc, calloc, realloc) --------> heap Q2/ // Count number of bits to be flipped // to covert A into B #include <iostream> using namespace std; // Function that count set bits int countSetBits(int n) { int count = 0; while (n) { count += n & 1; n >>= 1; } return count; } // Function that return count of // flipped number int FlippedCount(int a, int b) { // Return count of set bits in // a XOR b return countSetBits(a^b); } // Driver code int main() { int a = 10; int b = 20; cout << FlippedCount(a, b)<<endl; return 0; } Q4/Define the Following C Keywords ? #define?? #include?? #pragma?? #asm?? #ifdef...#endif? o #define define a macro o #include include a source file o #pragma is for compiler directives that are machine specific or operating system specific, i.e. it tells the compiler to do something, set some option, take some action, override some default, etc. that may or may not apply to all machines and operating systems. o #asm to include the assembly directive o #ifdef compile these lines if NAME is not defined o #endif to delimit the scope of these directives Pointers Quiz Solution
  • 4. 4 Q5/ The answers are: a) int a; // An integer b) int *a; // A pointer to an integer c) int **a; // A pointer to a pointer to an integer d) int a[10]; // An array of 10 integers e) int *a[10]; // An array of 10 pointers to integers f) int (*a)[10]; // A pointer to an array of 10 integers g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer Q6/ int *ptr; ptr = (int *)0x67a9; *ptr = 0xaa55; A more obscure approach is: *(int * const)(0x67a9) = 0xaa55; Q8/ /* * main.c * * Created on: Jun 16, 2017 * Author: Keroles Shenouda */ #include "stdio.h" struct Sbits { unsigned char bit012:3; unsigned char bit34:2; unsigned char bit5:1; unsigned char bit6:1; unsigned char bit7:1; } status; union registerType { unsigned char Byte; struct Sbits bits ; }; int main () { // define a pointer and cast it to point to the registers memory location union registerType *pReg = (union registerType*)0x00008000; // use the fields as pReg->bits.bit5 = 1; pReg->bits.bit012 = 7; // access the whole byte as pReg->Byte = 0x55; return 0 ; } Explanation: The first printf will print 10 20 30 40 The second printf will print 10 The Explanation In C, array parameters are always treated as pointers. So following two statements have the same meaning. void fun(int arr[]) void fun(int *arr) [] is used to make it clear that the function expects an array, it doesn’t change anything though. People use it only for readability so that the reader is clear about the intended parameter type. The bottom line is, sizeof should never be used for array parameters, a separate parameter for array size (or length) should be passed to fun(). So, in the given program, arr_size contains ration of pointer size and integer size, this ration= is compiler dependent. Q7/