Last active
April 14, 2023 20:32
-
-
Save jotux/1191965 to your computer and use it in GitHub Desktop.
Embedded C Interview Questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the expected output? | |
main() | |
{ | |
int a; | |
int b; | |
for (a = 0,b = 0;a < 10,b < 5;a++,b++) | |
{ | |
printf("%d %d\n",a,b); | |
} | |
return 0; | |
} | |
// This shows they know: | |
// - What the comma operator does | |
// Bonus points for the phrase "Why the hell would you do that?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the output? Why? | |
// What would happen if you strcpy a1? | |
void main() | |
{ | |
char a1[3] = "abc"; | |
char a2[8] = "abcdefgh"; | |
char b1[] = "abc"; | |
char b2[] = "abcdefgh"; | |
char* c1 = "abc"; | |
char* c2 = "abcdefgh"; | |
printf("a1:%s is size: %d\n",a1,sizeof(a1)); | |
printf("a2:%s is size: %d\n",a2,sizeof(a2)); | |
printf("b1:%s is size: %d\n",b1,sizeof(b1)); | |
printf("b2:%s is size: %d\n",b2,sizeof(b2)); | |
printf("c1:%s is size: %d\n",c1,sizeof(c1)); | |
printf("c2:%s is size: %d\n",c2,sizeof(c2)); | |
} | |
// This shows they know: | |
// -How memory is allocated for arrays, strings, and pointers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complete the code. What is the output? | |
typedef struct | |
{ | |
int a; | |
int b; | |
} new_type; | |
void f1(void *in); | |
main() | |
{ | |
new_type mine = {0,1}; | |
printf("%d %d\n",mine.a,mine.b); | |
f1( ); | |
printf("%d %d\n",mine.a,mine.b); | |
return 0; | |
} | |
void f1(void *in) | |
{ | |
new_type *blah = ; | |
printf("-%d %d-\n",blah->a,blah->b); | |
blah->a = 1; | |
} | |
// This shows they know: | |
// -Passing and casting structures | |
// -Typedefs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the expected output? | |
// Is this code portable? | |
main() | |
{ | |
char foo[8] = {1,0,2,0,3,0,4,0}; | |
short int *bar = &foo; | |
long int *derp = &foo; | |
int i; | |
for (i = 0;i < 4;i++) | |
{ | |
printf("0x%x\n",bar[i]); | |
} | |
for (i = 0;i < 2;i++) | |
{ | |
printf("0x%x\n",derp[i]); | |
} | |
return 0; | |
} | |
// This shows they know: | |
// -Pointer types | |
// -Endianness | |
// -Casting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complete the following macros | |
#define SET_BIT(reg,n) | |
#define CLEAR_BIT(reg,n) | |
#define TOGGLE_BIT(reg,n) | |
// This shows they know: | |
// -Basic embedded operations | |
// -Binary operators | |
// Describe static/extern/const/volatile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the expected output? | |
// Is this code portable? | |
// Are there problems with this code you would fix? | |
typedef struct | |
{ | |
char foo; | |
char bar; | |
} new_type; | |
typedef struct | |
{ | |
char my_str[3]; | |
new_type dat; | |
} other_type; | |
void f1(void *in); | |
main() | |
{ | |
other_type stuff = {'a','b','c',{1,2}}; | |
f1((void *)&stuff); | |
return 0; | |
} | |
void f1(void *in) | |
{ | |
new_type *other_stuff = (new_type *)(in + 3); | |
printf("%d %d\n",other_stuff->foo,other_stuff->bar); | |
} | |
// This shows they know: | |
// -Off-boundary memory access |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complete the declaration for CallFuncNumTimes. What is the expected output? | |
void func1() | |
{ | |
printf("1\n"); | |
} | |
void func2() | |
{ | |
printf("2\n"); | |
} | |
void CallFuncNumTimes( , int num_of_times) | |
{ | |
int cnt; | |
for (cnt = 0;cnt < num_of_times;cnt++) | |
{ | |
function(); | |
} | |
} | |
main() | |
{ | |
CallFuncNumTimes(func1, 5); | |
CallFuncNumTimes(func2, 5); | |
return 0; | |
} | |
// This shows they know: | |
// -Simple function pointers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You are using SimpleDelay() as a mechanism to delay execution. | |
// When you enable optimization the function no longer works. | |
// How can you change SimpleDelay() to make it work? | |
void SimpleDelay(unsigned long int cnt) | |
{ | |
unsigned long int i = 0; | |
while (i++ < cnt); | |
} | |
// This shows they know: | |
// -Compiler optimization | |
// -Volatile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the expected output? | |
main() | |
{ | |
int a = 0x05; | |
if (a & 0xF0 > 3) | |
{ | |
printf("true"); | |
} | |
else | |
{ | |
printf("false"); | |
} | |
return 0; | |
} | |
// This shows they know: | |
// -Order of execution in compilers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the expected output? | |
void func1(int var) | |
{ | |
static int foo; | |
printf("%d\n",foo); | |
foo = var; | |
} | |
void main() | |
{ | |
func1(1); | |
func1(2); | |
func1(3); | |
} | |
// This shows they know: | |
// -Static variables |
test 2.c
typedef struct
{
int a;
int b;
} new_type;
void f1(void *in);
main()
{
new_type mine = {0,1};
printf("%d %d\n",mine.a,mine.b);
f1((void*)&mine);
printf("%d %d\n",mine.a,mine.b);
return 0;
}
void f1(void *in)
{
new_type *blah = in;
printf("-%d %d-\n",blah->a,blah->b);
blah->a = 1;
}
We were building similar helpful resource. There are only three questions public at the moment but hope it helps-
https://www.adaface.com/assessment-test/embedded-c-online-programming-test
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer Test5.c
Output: 1 2