Frequently asked questions and answers of Terra in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best Terra Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download Terra FAQs in PDF form online for academic course, jobs preparations and for certification exams .
Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.
Question-1. What is Terra?
Answer-1: Terra is a low-level system programming language that is embedded in and meta-programmed by Lua.
Question-2. Who developed Terra?
Answer-2: Terra was developed by Zachary DeVito and collaborators at Stanford University.
Question-3. How do you install Terra?
Answer-3: You can install Terra from source or use a prebuilt binary from its official repository.
Question-4. How does Terra relate to Lua?
Answer-4: Terra extends Lua, allowing you to write and compile high-performance code using Lua as a meta-programming layer.
Question-5. How do you define a function in Terra?
Answer-5: Using terra function_name(args) body end.
Question-6. How do you call a Terra function from Lua?
Answer-6: By invoking the function like a regular Lua function.
Question-7. How do you print output in Terra?
Answer-7: Using C.printf("Hello, World!\n").
Question-8. How do you declare variables in Terra?
Answer-8: Using var x : int = 10.
Question-9. What types does Terra support?
Answer-9: It supports primitive types like int, double, bool, and structures.
Question-10. How do you perform arithmetic operations in Terra?
Answer-10: Using +, -, *, and / operators like in C.
Question-11. How do you define a structure in Terra?
Answer-11: Using struct Name { field1 : type, field2 : type }.
Question-12. How do you create an array in Terra?
Answer-12: Using var arr : int[10].
Question-13. How do you allocate memory in Terra?
Answer-13: Using C.malloc(size).
Question-14. How do you free allocated memory in Terra?
Answer-14: Using C.free(pointer).
Question-15. How do you perform loops in Terra?
Answer-15: Using for i = 0, N do body end.
Question-16. How do you use if conditions in Terra?
Answer-16: Using if condition then body end.
Question-17. How do you use elseif in Terra?
Answer-17: Using if condition then body elseif other_condition then other_body end.
Question-18. How do you define a Terra function returning a value?
Answer-18: Using terra function_name(args) : return_type body end.
Question-19. How do you pass parameters to a Terra function?
Answer-19: As function arguments, e.g., terra add(a : int, b : int) : int return a + b end.
Question-20. How do you return multiple values in Terra?
Answer-20: Using return value1, value2.
Question-21. What is the role of C.printf in Terra?
Answer-21: It allows calling C?s printf function for formatted output.
Question-22. How do you include C libraries in Terra?
Answer-22: Using C.include("library.h").
Question-23. How do you interact with Lua from Terra?
Answer-23: By using lua to call Lua functions or access Lua variables.
Question-24. How do you define a global variable in Terra?
Answer-24: Using global name : type = value.
Question-25. How do you create a function pointer in Terra?
Answer-25: Using var ptr : &FunctionType = function_name.
Question-26. How do you cast types in Terra?
Answer-26: Using @expression, e.g., @int(3.5).
Question-27. What is JIT compilation in Terra?
Answer-27: Terra functions are JIT-compiled, meaning they are compiled at runtime for efficiency.
Question-28. How do you use metaprogramming in Terra?
Answer-28: By writing Lua code that generates Terra code dynamically.
Question-29. How do you create a macro in Terra?
Answer-29: Using macro function_name(args) return terra code end.
Question-30. How do you interface Terra with existing C code?
Answer-30: By using C.include("header.h") and C.function_name().
Question-31. How do you create a function in Terra that works like a C function?
Answer-31: By defining functions similar to C syntax but using Terra?s features.
Question-32. What is the terra keyword used for?
Answer-32: It defines a function in Terra that can be JIT-compiled.
Question-33. How do you include external C functions in Terra?
Answer-33: Using C.declare("int myfunc(int)");.
Question-34. How do you optimize performance in Terra?
Answer-34: By using low-level memory management and metaprogramming.
Question-35. How do you run Terra code inside Lua?
Answer-35: By using terra.loadstring("terra code")().
Question-36. What is the difference between Terra and Lua?
Answer-36: Lua is an interpreted scripting language, while Terra is a compiled low-level language.
Question-37. Can Terra generate standalone executables?
Answer-37: No, but it can generate compiled object files or libraries.
Question-38. How do you compile a Terra function?
Answer-38: By calling .compile() on the function.
Question-39. How do you call a Terra function from Lua?
Answer-39: By treating it like a Lua function.
Question-40. How do you create an anonymous function in Terra?
Answer-40: Using terra (args) body end.
Question-41. What is type inference in Terra?
Answer-41: Terra can automatically infer types based on usage.
Question-42. How do you use an and condition in Terra?
Answer-42: Using if (a and b) then body end.
Question-43. How do you handle errors in Terra?
Answer-43: By checking return values and using Lua error handling.
Question-44. What is the default integer size in Terra?
Answer-44: The default size is platform-dependent but usually int32.
Question-45. How do you link multiple Terra files?
Answer-45: Using require("filename").
Question-46. How do you generate assembly from Terra code?
Answer-46: Using .printpretty().
Question-47. How do you interact with hardware in Terra?
Answer-47: By using low-level memory operations and calling C libraries.
Question-48. Can Terra work with GPUs?
Answer-48: Yes, by using CUDA or OpenCL libraries.
Question-49. How do you write a recursive function in Terra?
Answer-49: Using terra function_name(args) return function_name(new_args) end.
Question-50. Why use Terra over C?
Answer-50: Terra provides metaprogramming capabilities while maintaining C-like performance.
Frequently Asked Question and Answer on Terra
Terra Interview Questions and Answers in PDF form Online
Terra Questions with Answers
Terra Trivia MCQ Quiz